Next: Comparing Strings
Up: test: Comparisons
Previous: Testing/Comparing Numbers
To test file types, a number of primitives are used (taken from
[7, p. 439]):
- checks that the file exists and is not empty.
- checks that the file is an ordinary file
(not a directory).
- checks whether the file is really a directory.
- checks that the file is executable.
- checks that the file is writeable.
- checks that the file is readable.
An example would be where a program needs to output something
to a file, but first checks that the file exists:
if test ! -s arg.file
echo "arg.file is empty or does not exist."
ls -l > arg.file
echo "File arg.file already exists."
Note the exclamation mark within the test sequence.
The exclamation mark means ``not".