java - Passing a space-separated System Property via a shell -
i'm having difficulties startup java program shell script (bash) nested variables used. there many system , -d java properties need passed java program. organise them in nicer way 1 below difficult read when in 1 line.
this similar "passing space-separated system property via shell script doesn't work" not same.
here stripped down sample. imagine java program this:
public class main { public static void main(string[] args) { (string s : args) { system.out.println(s); } } }
when invoking this:
java main "first_line" "second line spaces"
it give ok result response:
first_line second line spaces
however if script used:
#!/bin/sh param01="firstline" param02="second line spaces" params="$param01 $param02" java main $params
then spaces eaten , second parameter passed unquoted java. result looks this:
firstline second line spaces
have tried differently quote variables in shell script, far without success. how quote shell variables spaces preserved , parameter passed intact java?
if put shell variable on command line unquoted, undergoes word splitting. prevent word splitting, keep each parameter in double-quotes:
java main "$param01" "$param02"
or, if want fancy, use array:
params=("$param01" "$param02") java main "${params[@]}"
Comments
Post a Comment