Problem
I am trying to test for the existence of a file using the "-e" option to the test(C) command (or its counterpart, "["). For example, to test for the file "filename", use:
test -e filename<or>[ -e filename ]The "test" function is built-in to both the Bourne shell, sh, and
the Korn shell, ksh. Both sh(C) and ksh(C) man pages refer to the
test(C) man page for detailed description. The "-e" option is one
of the options detailed in this man page.The "-e" option seems to work fine under ksh. But under sh, I get
the following error:test: argument expected Cause
The "-e" option to test was introduced in SCO OpenServer Release 5. It was incorporated into the ksh program, but this feature was not added to the sh program.
Solution
This has been reported to SCO Engineering. If you are using the Bourne shell, sh, and wish to test for a file's existence, there are several workarounds you can use:
1. Run in the Korn shell, ksh, environment. At the Bourne
shell prompt, type:ksh -o vi-or-exec ksh -o vi2. Run shell scripts that include "test -e" in the ksh environment by adding, as the first line of such scripts, the following:
#!/bin/ksh3. Modify "-e" test statements and the /bin/test and /bin/[ files. To modify the "-e" test statements, change all of these statements in your scripts as:
change: "test -e" --> "/bin/test"-and-change: "[" --> "/bin/["Next, modify the /bin/test and /bin/[ files by adding the following as the first line to each file:
#!/bin/ksh4. Alternative to the "-e" option, reconstruct your test using
one or more of the other test options available, as "-f",
"-d", "-r", "-s", etc. See also
Manual pages: test(C), sh(C), ksh(C)