Search code examples
bashvariablesquotes

bash shell pass variable and quotes


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


Solution

  • You can do it like this

    java --jar myapp.jar $(echo "'$myvar'")
    

    But why not just use double quotes?