I have a find command:
find Directory/{Alpha,Bravo,Charlie} arg1 arg2
I want to replace Alpha,Bravo,Charlie
with $find_dir
find Directory/{$find_dir} arg1 arg2
however the latter expands to
find Directory/{Alpha,Bravo,Charlie} arg1 arg2
rather then
find Directory/Alpha Directory/Bravo Directory/Charlie arg1 arg2
Why? It's part of a fairly complex bash script that may have more or less directories, not all which are relevant (so globbing Upload/* would not work). So if I setup three now and add another, I'll have to manually add it in later. Plus I need it run from the root of directories to keep finds outputs perspective (./Upload/Dir/file as opposed to ./Dir/file).
But using a variable would permit me to change that as needed and keep it relevant to other parts of the script.
and any characters special to other expansions are preserved in the result
. ForThe order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution
, you missed the important thing, they are done from left to right. You can trya=1; echo $a $((a++)) {0..$a}
and see the result. If brace expansion was done first, you must get1 1 1
, but the result is1 1 2
. – cuonglm Oct 29 '14 at 02:301 1 {0..1}
, but the result is1 1 {0..2}
– cuonglm Oct 29 '14 at 02:39