问题
I want to expand tar parameter --exclude
thru variable like:
set -x verbose
EXC=AAA,BBB
echo --exclude={$EXC} > /dev/null
Output:
echo '--exclude={AAA,BBB}'
But I expect:
echo --exclude=AAA --exclude=BBB
I tried different invocations, but nothing.. Whats wrong?
回答1:
You need to use eval
to parse the line after substituting the variable.
eval "echo --exclude={$EXC}"
来源:https://stackoverflow.com/questions/17673337/bash-expand-parameters-from-variable-how