2

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.

Jake
  • 14,667
  • 21
  • 68
  • 85
  • Also on http://stackoverflow.com/questions/102049/how-do-i-escape-the-wildcard-asterisk-character-in-bash/102075#102075 – Bhavesh K. Aug 20 '13 at 17:49

2 Answers2

3
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!"

Dennis Williamson
  • 324,833
  • 88
  • 366
  • 429
1

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

Use an array instead.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325