How to escape wildcard expansion in a variable in bash?

老子叫甜甜 提交于 2019-12-24 00:28:25

问题


How do I escape a wildcard expansion in a variable name?

CP="lib/*"
COMMAND="java $VARIABLES -cp $CP SomeClass"
echo $COMMAND

Echoing the command always causes wildcard expansion.


回答1:


echo "$COMMAND"

Using quotes prevents the glob from being expanded.

By the way, see "I'm trying to put a command in a variable, but the complex cases always fail!"




回答2:


"I'm trying to put a command in a variable, but the complex cases always fail!"

Use an array instead.



来源:https://stackoverflow.com/questions/10888764/how-to-escape-wildcard-expansion-in-a-variable-in-bash

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