Evaluates conditional expressions.
test Expression
OR
[ Expression ]
The test command evaluates the Expression parameter, and if the expression value is True, returns a zero (True) exit value. Otherwise, the test command returns a nonzero (False) exit value. The test command also returns a nonzero exit value if there are no parameters.
Notes:
Functions and operators are treated as separate parameters by the test command. The Expression parameter refers to a statement that is checked for a true or false condition. The following functions are used to construct this parameter:
These functions can be combined with the following operators:
! | Unary negation operator |
-a | Binary AND operator |
-o | Binary OR operator ( that is, the -a operator has higher precedence than the -o operator) |
\(Expression\) | Parentheses for grouping |
This command returns the following exit values:
0 | The Expression parameter is true. |
1 | The Expression parameter is false or missing. |
>1 | An error occurred. |
if test ! -s "$1" then echo $1 does not exist or is empty. fi
If the file specified by the first positional parameter to the shell procedure, $1, does not exist, the test command displays an error message. If $1 exists and has a size greater than 0, the test command displays nothing.
Note: There must be a space between the -s function and the file name.
The quotation marks around $1 ensure that the test works properly even if the value of $1 is a null string. If the quotation marks are omitted and $1 is the empty string, the test command displays the error message test: argument expected.
if [ $# -lt 2 -o ! -e "$1" ] then exit fi
If the shell procedure is given fewer than two positional parameters or the file specified by $1 does not exist, then the shell procedure exits. The special shell variable $# represents the number of positional parameters entered on the command line that starts this shell procedure.
The Shells Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices describes shells in general, defines terms that are helpful in understanding shells, and describes the more useful shell functions.
/usr/bin/test | Contains the test command. |
The bsh command, csh command, find command, ksh command, sh command.
Shells Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.