Assuming that you are using a shell that is compatible with the Bourne shell; e.g. sh, bash, ksh, etc, the following wrapper will pass all command line arguments to the java command:
#!/bin/sh
OPTS=...
java $OPTS com.example.YourApp "$@"
The $@
expands to the remaining arguments for the shell script, and putting quotes around it causes the arguments to be individually quoted, so that the following will pass a single argument to Java:
$ wrapper "/home/person/Stupid Directory Name/foo.txt"
Without the double quotes around "$@"
in the wrapper script, Java would receive three arguments for the above.
Note that this does not work with "$*"
. According to the bash
manual entry:
"$*"
is equivalent to "$1c$2c..."
, where c
is the first character of the value of the IFS
variable.
In other words, all shell arguments would be concatenated into a single command argument for your Java application, ignoring the original word boundaries.
Refer to the bash
or sh
manual ... or the POSIX shell spec ... for more information on how the shell handles quoting.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…