I have a script that should redirect all its parameters to another program. In addition, for clarity, I support the shell option nounset.
Consider the following script example:
#!/bin/ksh
set -o nounset
printf "<%s>\n" "Parameter count: $#" "$@"
The above works fine as long as the main script call has at least one parameter. If it has no parameters, this results in ksh: @: parameter not set, and the script exits.
$ ./dollar_at.sh "Hello" "World"
<Parameter count: 2>
<Hello>
<World>
$ ./dollar_at.sh ""
<Parameter count: 1>
<>
$ ./dollar_at.sh
./dollar_at.sh[5]: @: parameter not set
If I disable the option nounset, we get the following:
$ ./dollar_at.sh
<Parameter count: 0>
By the way, nounsetin it bashprocesses empty $@without errors, but the environment for this script does not have bashas an option.
ksh $@?
, "$@" , , bash ksh nounset .
, :
if (( $# > 0 )) $@. , , , .nounset , $@. nounset.