bourne shell if [ -e $directory/file.$suffix ]
The Bourne shell is somewhat of an antique. The Solaris version doesn't have the -e
operator for the test
(a.k.a. [
) builtin that was introduced somewhat late in the life of the Bourne shell¹ and enshrined by POSIX.
As a workaround, you can use -f
to test for the existence of a regular file, or -r
if you aren't interested in unreadable files.
Better, change #!/bin/sh
to #!/usr/xpg4/bin/sh
or #!/bin/ksh
so as to get a POSIX shell.
Beware that [ $option -eq 9 ]
is probably not right: -eq
is a numerical comparison operator, but $option
isn't really numeric — it's a date. On a 32-bit machine, when 201301271355
is interpreted as a number, it is taken modulo 232. It so happens that no date in the 21st century is very close to 0 modulo 232, but relying on this is very brittle. Make this [ "$option" = 9 ]
instead.
As a general shell programming principle, always put double quotes around variable and command substitutions: "$foo"
, "$(foo)"
. If you don't, the shell splits the result at each whitespace character and treats each resulting word as a filename wildcard pattern. So an unprotected $foo
is only safe if the value of foo
does not contain any whitespace or \[?*
. Play it safe and always use double quotes (unless you intend the splitting and pattern matching to happen).
¹ Or was it a ksh addition never ported to Bourne? I'm not sure.