How to escape wildcard expansion in a variable in bash?
Asked Answered
G

2

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.

Gauldin answered 4/6, 2012 at 21:40 Comment(1)
Also on #102549Muticous
T
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!"

Teem answered 4/6, 2012 at 21:57 Comment(0)
P
1

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

Use an array instead.

Parchment answered 4/6, 2012 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.