Jake
Jake

Reputation: 15217

How to escape wildcard expansion in a variable in bash?

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.

Upvotes: 3

Views: 2309

Answers (2)

Dennis Williamson
Dennis Williamson

Reputation: 359905

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

Upvotes: 4

Related Questions