Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a space-separated System Property via a shell script doesn't work

Tags:

java

bash

I have this bash file:

#/bin/bash

PROP="-Dprop=foo bar"

java $PROP -jar Foo.jar

So, what I want to do here is pass a space-separated list as a System Property. But this somehow does not work:

Caused by: java.lang.ClassNotFoundException: bar

So, it seems that Bash breaks -Dprop=foo bar up into -Dprop=foo, bar. I tried everything from double quoting to escaping the space character but nothing seems to work.

like image 370
helpermethod Avatar asked Nov 21 '11 15:11

helpermethod


1 Answers

You need to add the quotation marks around the shell script $ variable:

PROP="-Dprop=foo bar"

java "$PROP" -jar Foo.jar
like image 61
Stephen C Avatar answered Oct 24 '22 04:10

Stephen C