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

前端 未结 3 1861
灰色年华
灰色年华 2020-12-11 17:32

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 li

相关标签:
3条回答
  • 2020-12-11 17:50

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

    PROP="-Dprop=\"foo bar\""
    
    0 讨论(0)
  • 2020-12-11 17:55

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

    PROP="-Dprop=foo bar"
    
    java "$PROP" -jar Foo.jar
    
    0 讨论(0)
  • 2020-12-11 17:59

    Set the property as follows if there are spaces in the property value with multiple values;

    PROP="-Dprop=foobar"
    PROP="$PROP -DpropTwo='hello world'"
    
    java "$PROP" -jar Foo.jar
    
    0 讨论(0)
提交回复
热议问题