Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bash shell which I need to modify, and I have to set a variable in a script and then call another script. My variable, EXTRA_JAVA_OPTIONS must be

-javaagent:myagent.jar="-d 0 -i 1000 -l log2 -c log1"

So what I did is

export EXTRA_JAVA_OPTIONS="-javaagent:myagent.jar=\"-d 0 -i 1000 -l log2 -c log1 \""

Then I call my script and inside my script there is the following :


However, this won't produce the result I desire. Running bash -x I can see that

+ /usr/java/jdk1.6.0_38/bin/java '-javaagent:myagent.jar="-d 0 -i 1000 -l log2 -c log1"'

If on the contrary I do:


I got a different version of the output, which is wrong too

+ /usr/java/jdk1.6.0_38/bin/java '-javaagent:myagent.jar="-d' 0 -i 1000 -l log2 -c 'log1"'

How do I prevent ' from appearing when printing my strings, or them to be added by the shell?

share|improve this question
Weird. What does "$JAVACMD $EXTRA_JAVA_OPTIONS" do? Or just plain no quotes at all? – goldilocks Jan 11 '13 at 16:05
Did you mean to pass a single argument to java containing among others two " characters? You show several things that go wrong, but what is your desired result (making sure to distinguish between any quoting that you're using for presentation, and quotes and whitespace that must end up in an argument passed to java)? – Gilles Jan 11 '13 at 23:43

The quotes are just to prevent splitting by word. But you already have quotes around the whole thing.

export EXTRA_JAVA_OPTIONS="-javaagent:myagent.jar=-d 0 -i 1000 -l log2 -c log1"
share|improve this answer

Using an array is a safe way to keep your arguments containing whitespace intact:

EXTRA_JAVA_OPTIONS=(-javaagent:myagent.jar="-d 0 -i 1000 -l log2 -c log1")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.