#!/bin/bash
# this works: java '-XX:OnOutOfMemoryError=nohup bash -c "service jira stop;service jira stop" &' -version
JVM_SUPPORT_RECOMMENDED_ARGS="" # WHAT TO PUT HERE !?! so the last line will execute the command above?
JAVA_OPTS=" ${JAVA_OPTS} ${JVM_REQUIRED_ARGS} ${DISABLE_NOTIFICATIONS} ${JVM_SUPPORT_RECOMMENDED_ARGS} ${JVM_EXTRA_ARGS} ${JIRA_HOME_MINUSD}"
set -x
java $JAVA_OPTS -version
If possible don’t touch other lines than the JVM_SUPPORT_RECOMMENDED_ARGS one.
Although @raukh’s answer is right, i.e. you have to escape the
", you are also missing another point.Answer for the impatient: you need to add
\"around${JVM_SUPPORT_RECOMMENDED_ARGS}also, to prevent bash from separating the contents ofJVM_SUPPORT_RECOMMENDED_ARGSto different argument.Complete answer:
Imagine this example, assuming
print_argsis a program that echoes its arguments each in one lineThis will output
aandbas separate arguments. This is because the"is removed and in fact the executed command is:To make your command see your variable all as one parameter, you have to put it in
":Will show
a bas one argument.Even if you write extra
"in your string, it won’t work, as bash will separate the contents of the variable anyway:will give you
"aandb"as separate arguments. The only way you can handle this, is to add"where you use the variable, instead of where you define it.So in your case, the solution is this:
The first line is as raukh suggested. The second line has added
\"around${JVM_SUPPORT_RECOMMENDED_ARGS}.If you want to test this, here is an example: