2012-08-20 19:44:51 +0200, Roman Rakus: [...] > And how would you achieve to fill array with all file names > containing `[1]=' for example. [...]
Another interesting question is how to fill the array with all the file names that start with a digit followed by "=". $ touch {3..5}=foo $ ls 3=foo 4=foo 5=foo $ bash -c 'a=([0-9]=*); typeset -p a' bash: [0-9]=*: bad array subscript declare -a a='()' $ bash -c 'shopt -s extglob; a=(@([0-9])=*); typeset -p a' bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `shopt -s extglob; a=(@([0-9])=*); typeset -p a' $ bash -c 'shopt -s extglob a=(@([0-9])=*); typeset -p a' declare -a a='([0]="3=foo" [1]="4=foo" [2]="5=foo")' > Definitely it's good, if you want to be sure, to always quote all > characters which means pathname expansion - `*', `?' and `['. [...] Yes, the problem here is that "[" is overloaded in a conflicting manner as a globbing operator and that poorly designed special type of array assignment. Quoting them will prevent both, it become more tricky if you want only one or the other. Note that in bash that also means we need to quote variables in there even if IFS is set to "". $ bash -c 'a="*"; b=([1]=$a); typeset -p b' declare -a b='([0]="[1]=bar")' -- Stephane