If you've been reading this
of articles in order, you saw the
script that accepted just one command-line argument.
If you put
in a script, the shell will replace that string
set of the script's command-line arguments.
Then you can pass as many arguments as you want, including pathnames
unusual characters (23.11
zpg report memo "savearts/What's next?"
The third argument has a perfectly legal filename; we see more and more of them
on our system - especially filesystems that are networked to computers
like the Macintosh, where spaces and other "special" characters in
filenames are common.
Double-quoting all arguments through the script helps to be sure that
the script can handle these unusual (but legal!) pathnames.
In this case, we want the arguments to be passed to the gzcat
Let's change the zpg
script to read:
gzcat "$@" >$temp
When the shell runs the script with the arguments shown above,
the command line will become:
gzcat "report" "memo" "savearts/What's next?" >/tmp/zpg12345
On some Bourne shells, if there are no command-line arguments,
becomes a single empty argument (46.7
as if you'd typed this:
gzcat "" >/tmp/zpg12345
In this case, the gzcat
command would complain that it can't find a
(Of course, in this script, the case
would prevent this problem.
But not all scripts test the number of arguments.)
On those shells, you can replace
That means that if
should be used.
A less-good fix is to replace
It gives you an unquoted list of command-line arguments; that's usually fine
but can cause trouble on pathnames with special characters in them.