3

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
  • 15,007
  • 22
  • 70
  • 86
  • 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

4
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
  • 346,391
  • 90
  • 374
  • 439
1

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

Use an array instead.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358