Bash: expand parameters from variable. How?

為{幸葍}努か 提交于 2019-12-10 12:08:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!