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
Post a Comment