Can I do filename pattern matching in a bash script?
- by Bob Bowden
Can I do filename pattern matching in a bash script?
"test" is a directory with the following files ...
bob@bob-laptop:~/test$ ls
exclude exclude1 exclude2 include1 include2
from the command line, if I want to exclude some of the files, I
can do ...
bob@bob-laptop:~/test$ echo !(exclude*)
include1 include2
but, if I put that command in a script (named exclude) ...
bob@bob-laptop:~/test$ cat exclude
echo !(exclude*)
when I execute it, I get an error ...
bob@bob-laptop:~/test$ ./exclude
./exclude: line 1: syntax error near unexpected token ('
./exclude: line 1:echo !(exclude*)'
I've tried every (I think) variation of escaping some, all or
none of the special characters and I still get an error.
What am I missing here? If I can't do this, would someone
please be so kind as to explain why?