How to escape extended pathname expansion patterns in quoted expressions?
问题 In addition to the basic * , ? and [...] patterns, the Bash shell provides extended pattern matching operators like !(pattern-list) ("match all except one of the given patterns"). The extglob shell option needs to be set to use them. An example: ~$ mkdir test ; cd test ; touch file1 file2 file3 ~/test$ echo * file1 file2 file3 ~/test$ shopt -s extglob # make sure extglob is set ~/test$ echo !(file2) file1 file3 If I pass a shell expression to a program which executes it in a sub-shell, the