Reputation: 925
I have a variable, which contains all types of characters
myvar="alfanum;001String"
and I need to pass them to a command with a single quotes in this way
java -jar myapp.jar HERE I NEED TO PUT -> 'alfanum;001String' with single quotes
but if I do
java -jar myapp.jar "'$myvar'"
it doesn't work.
Note I can't use just double quotes:
java -jar myapp.jar "$myvar"
because $myvar
is a user's input and myapp.jar need to retrieve it rounded with a single quotes
Thank you
Upvotes: -1
Views: 1064
Reputation: 2201
You can mix several quote types together to form a string in singe quotes:
"'""$myvar""'"
will expand to 'alfanum;001String'
. You're probably need just "$myvar"
here though.
Upvotes: 2
Reputation: 7650
You can do it like this
java --jar myapp.jar $(echo "'$myvar'")
But why not just use double quotes?
Upvotes: 0