Passing a spatially separated system property through a shell script does not work

I have this bash file:

#/bin/bash

PROP="-Dprop=foo bar"

java $PROP -jar Foo.jar

So what I want to do is pass the list, separated by spaces, as a system property. But this somehow does not work:

Caused by: java.lang.ClassNotFoundException: bar

So, it seems that bash splits -Dprop=foo baron -Dprop=foo, bar. I tried everything: from double quoting to escaping a space, but nothing works.

+5
source share
2 answers

You need to add quotes around the shell of the script $ variable:

PROP="-Dprop=foo bar"

java "$PROP" -jar Foo.jar
+13
source

Try PROP = -Dprop = "foo bar" Or you could do

PROP="-Dprop=\"foo bar\""
-1
source

All Articles