You'd get that error message if you had turned the -u
option either by invoking ksh
as ksh -u
or ksh -o nounset
or by running set -u
or set -o nounset
.
touch $var1 $var2 $var3
is wrong anyway unless those variables are meant to contain lists of file patterns.
It should have been:
touch -- "$var1" "$var2" "$var3"
Now, if you want to allow one of them to be empty and not pass it as an empty argument to touch
in that case (and work around set -u
), you'd write:
touch -- ${var1:+"$var1"} ${var2:+"$var2"} ${var3:+"$var3"}
Another option is to do:
(IFS=; set -f +u; touch -- $var1 $var2 $var3)
With IFS=
, we disable word splitting, with set -f
globbing, but we rely on the third side-effect of leaving variables unquoted: empty removal. (and we also disable nounset
with set +u
, all of that in a subshell only).