Bash script: variable output to rm with single quotes -
i'm trying pass parameter rm in bash script clean system automatically. example, want remove except *.doc files. wrote following codes.
#!/bin/bash remove_target="!*.txt" rm $remove_target however, output say
rm: cannot remove ‘!*.txt’: no such file or directory it bash script add single quotes me when passing variable rm. how can remove single quotes?
using bash
suppose have directory 3 files
$ ls a.py  b.py  c.doc to delete except *.doc:
$ shopt -s extglob $ rm !(*.doc) $ ls c.doc !(*.doc) extended shell glob, or extglob, matches files except ending in .doc.
the extglob feature requires modern bash.
using find
alternatively:
find . -maxdepth 1 -type f ! -name '*.doc' -delete 
Comments
Post a Comment