How to escape wildcard expansion in a variable in bash?

2.2k views Asked by At

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.

2

There are 2 answers

0
Dennis Williamson On BEST ANSWER
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!"

0
Ignacio Vazquez-Abrams On