DaemonFreerider
DaemonFreerider

Reputation: 15

How to escape single quote from parsing inside command?

I have to start the command at the bottom as a specific user in a script. the parameter $vmargs needs to be in single quotes ('$vmargs'). im stuck here because its always parsed. the vmargs parameter has some java options within.

 su synesty -c "screen -dmS appscreen ./eclipse -vmargs 
                -DAPP_ENV=$automatey_note  $vmargs"

Hope anyone can help.

Update: Sorry I saw my question was not clear. The parameter have to be solved.

 '-DencryptorCredentials=currentPass|oldPass|1 -Xms512m -Xmx2048m 
 -DLOGGING_HOME=configuration/ -Djava.io.tmpdir=/tmp -Dorg.osgi.service.http.port=8081
 -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Xdebug         
 -Xnoagent
 -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n 
 -Djava.net.preferIPv4Stack=true -DapplyDbMigrations=true -XX:MaxPermSize=128m     
 -XX:-HeapDumpOnOutOfMemoryError '

Thats the stuff and I need the single quotes, otherwise shell will not recognize it as parameters

Upvotes: 0

Views: 272

Answers (2)

crw
crw

Reputation: 685

If you want to pass $vmargs to su synesty unchanged, "escape" the dollar which will preserve the string as-is:-

su synesty -c "screen -dmS appscreen ./eclipse -vmargs -DAPP_ENV=$automatey_note \$vmargs"

Upvotes: 1

dogbane
dogbane

Reputation: 274582

Just put single quotes around $vmargs. It will still be expanded because the whole thing is in double-quotes.

su synesty -c "screen -dmS appscreen ./eclipse -vmargs -DAPP_ENV=$automatey_note '$vmargs'"

Upvotes: 1

Related Questions