Oh brother, this is one of the reasons UNIX was much more developer-friendly.
PROPS="-Dprop1=foo bar -Dprop2=bar foo"
java $PROPS SomeClass.class
You can try to escape with backslashes and what not but it becomes fairly hard if not impossible to expand multiple parameters correctly as a single variable. I believe one solution is to use arrays and another is just not use arguments and instead rely on other configuration mechanisms (env variables, files, etc).You see this often rear its ugly head with daemon scripts.
I left an example of an argument with a space in there (the last one).
PROPS=("-Dprop1=foo" "bar" "-Dprop2=bar foo")
java "${PROPS[@]}" SomeClass.class
(The quotes around `${PROPS[@]}` is important.) Do note, there is an unfortunate edge case here if PROPS is empty, you'll get a false `""` arg passed to java in that case. There's a less pleasant syntax that avoids that issue but I don't recall it off-hand.(edit: Please read the replies to my post, I didn't think about the fact that this syntax is bash specific. Thanks to those who pointed it out)
I tried to find a failsafe solution once while rewriting a daemon script and just gave up.
PROPS="'-Dprop1=foo bar' '-Dprop2=bar foo'"It's a sensible rule, when you think about it - otherwise, for example, an expansion that introduced mismatched quotes would cause total chaos.
Example
#!/bin/bash
Q1="'"
Q2='"'
echo "$Q1$Q2"
This prints '"
And if you really understand that ' and " turn quoting on and off anywhere in the line, you can combine these two into a single variable: #!/bin/bash
Q1="'"'"'
echo "$Q1"If it's an issue for you on Linux, you can always run a python shell and spawn your process there. On Windows you can't.
If you want spaces to be unparsed in parameters, you "quote" the parameter.
A="spaces in the argument"
touch "$A"
ls -l
total 0
-rw-rw-r-- 1 me me 0 Dec 27 15:40 a file with spaces