I want to write a wrapper bash script, and to pass all arguments to a called program. I was very sure, that this works correctly:
#!/bin/sh
someProgam $@
But when passing exotic arguments (empty, unescaped, in quotes, ...) this fails.
For example: without the wrapper script, someProgram "1 2" 3
results in the arguments
[1 2]
and [3]
.
But called from the script, I get [1]
, [2]
, [3]
.
Braces are just for visualization.
NOTE: It's a Java program, which is called. But I think it doesn't matter.
to augment ndim's answer: the behavior of
"$@"
is not specific to bash. it's prescribed by the Single Unix Specification:See also the bash docs on special parameters.
BTW1,
"$@"
is not specific to bash. You can probably rely on"$@"
in cross-platformsh
scripts to be run just about anywhere.BTW2, in case this happens to be the last line in that script, you can save your operating system a few bytes and an entry in the process table by changing the line to something like