Bash: Brace expansion in scripts not working due to unwanted escaping -


i want in bash script. i'm using bash 4.1.10.

# rm -rf /some/path/{folder1,folder2,folder3} 

works nicely (and expected) shell itself. deletes 3 desired folders leaving others untouched.

when put script unwanted happens. example, script:

#!/bin/bash set -x var="folder1,folder2,folder3" rm -rf /some/path/{$var} 

when execute script, folders not deleted.

i think due fact unwanted quoting occurring. output script using #!/bin/bash -x:

rm -rf '/some/path/{folder1,folder2,folder3}' 

which of course cannot succeed due ' marks.

how can working within script?

according the man page:

the order of expansions is: brace expansion, tilde expansion, parameter, variable , arithmetic expansion , command substitution (done in left-to-right fashion), word splitting, , pathname expansion.

so around this, add level of expansion:

eval "rm -rf /some/path/{$var}" 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -