Passing multiple jvm arguments containg spaces in one bash variable
<p>I have a small java program:</p>

<pre>

    public class Test {
      public static void main(String[] args) {
        System.out.println("A: " + System.getProperty("A"));
        System.out.println("B: " + System.getProperty("B"));
      }
    }

</pre>

<p>It works like this:</p>

<pre>

    # java -DA="A B" -DB="B A" Test
    A: A B
    B: B A

</pre>

<p>Now let's assume that someone is going to execute my program from bash like this, and I have no way to change it:</p>

<pre># java "$PARAMS" Test</pre>

<p>I have the values of A and B in bash variables, both of them containing spaces, like this:</p>

<pre>

    # A="A B"
    # B="B A"

</pre>

<p>how can I set the value of the PARAMS variable so that it would work fine?</p>

<p>I've tried this:</p>

<pre>

    # PARAMS="-DA=\"$A\" -DB=\"$B\""
    # echo $PARAMS
    -DA="A B" -DB="B A"

</pre>

<p>It seems that everything is fine, the value of $PARAMS is exactly the same as in the example above, but this is what I get:</p>

<pre>

    # set -x; java "$PARAMS" Test; set +x
    + set -x
    + java '-DA="A B" -DB="B A"' Test
    A: "A B" -DB="B A"
    B: null
    + set +x

</pre>

<p>So upon evaluating the PARAMS variable it is surrounded by single quotes thus java interprets it as a single variable A = '"A B" -DB="B A"'</p>

<p>So the question is how can I set the value of PARAMS using A and B to be evaluated as expected?</p>

<p>Thanks</p>