Name

test

Synopsis

                     test 
                     condition
                     [ 
                     condition 
                     ]
                  

Evaluate a condition and, if its value is true, return a zero exit status; otherwise, return a nonzero exit status. An alternate form of the command uses [ ] rather than the word test. condition is constructed using the following expressions. Conditions are true if the description holds true.

File conditions

-a file

file exists.

-b file

file is a block special file.

-c file

file is a character special file.

-d file

file is a directory.

-e file

file exists.

-f file

file is a regular file.

-g file

file has the set-group-ID bit set.

-h file

file is a symbolic link.

-k file

file has its sticky bit (no longer used) set.

-p file

file is a named pipe (FIFO).

-r file

file is readable.

-s file

file has a size greater than 0.

-t [n]

The open file descriptor n is associated with a terminal device (default n is 1).

-u file

file has its set-user-ID bit set.

-w file

file is writable.

-x file

file is executable.

-G file

file’s group is the process’s effective GID.

-L file

file is a symbolic link.

-N file

file has been modified since its last time of access.

-O file

file’s owner is the process’s effective UID.

-S file

file is a socket.

f1 -ef f2

Files f1 and f2 are linked (refer to the same file through a hard link).

f1 -nt f2

File f1 is newer than f2.

f1 -ot f2

File f1 is older than f2.

String conditions

-n s1

String s1 has nonzero length.

-o s1

Shell option s1 is set. Shell options are described under the set built-in command.

-z s1

String s1 has 0 length. ...

Get Mac OS X Panther in a Nutshell, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.