test
expression or [
expression ]
Arguments The following arguments are used to construct this parameter. All arguments return True if the object (file or string) exists, and the condition specified is true. For the -x argument, if the specified file exists and is a directory, the True exit value indicates that the current process has permission to change cd into the directory. ====Non standard
Korn Shell extensions==== file1
-nt file2 - file1 is newer than file2 file1
-ot file2 - file1 is older than file2 file1
-ef file2 - file1 is another name for file2 - (
symbolic link or
hard link)
String arguments In
Perl, these sections are reversed: eq is a string operator and == is a numerical operator, and so on for the others.
-n String1 - the length of the String1 variable is nonzero
-z String1 - the length of the String1 variable is 0 (zero) String1
= String2 - String1 and String2 variables are identical String1
!= String2 - String1 and String2 variables are not identical String1 - true if String1 variable is not a null string
Number arguments Integer1
-eq Integer2 - Integer1 and Integer2 variables are
algebraically equal
-ne - not equal
-gt - greater than
-ge - greater or equal
-lt - less than
-le - less or equal
Operators test arguments can be combined with the following operators:
! - Unary negation operator
-a - Binary AND operator
-o - Binary OR operator (the -a operator has higher precedence than the -o operator)
\(Expression\) - Parentheses for grouping must be escaped with a backslash \ The -a and -o operators, along with parentheses for grouping, are XSI extensions and are therefore not portable. In portable shell scripts, the same effect may be achieved by connecting multiple invocations of test together with the && and || operators and parentheses.
Exit status 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 ==Examples==