TEST(1)
NAME
test − condition command
USAGE
test expr
DESCRIPTION
Test evaluates the expression expr. If the value of expr is true, then test returns a zero exit status; otherwise, it returns a non-zero exit status. It also returns a non-zero exit if there are no arguments.
Use the following primitives to construct expr.
−r file True if the file exists and is readable.
−w file True if the file exists and is writable.
−f file True if the file exists and is not a directory.
−d file True if the file exists and is a directory.
−s file True if the file exists and has a size greater than zero.
−t [ fildes ]
True if the open file whose file descriptor number is fildes (1 by default) is associated with a terminal device.
−z s1 True if the length of string s1 is zero.
−n s1 True if the length of the string s1 is nonzero.
s1 = s2 True if the strings s1 and s2 are equal.
s1 != s2 True if the strings s1 and s2 are not equal.
s1 True if s1 is not the null string.
n1 −eq n2
True if the integers n1 and n2 are algebraically equal. You may use any of the comparisons −ne, −gt, −ge, −lt, or −le in place of −eq.
Combine these primaries with the following operators:
! Unary negation operator.
−a Binary and operator.
−o Binary or operator.
( expr )
Parentheses for grouping.
Note that −a has higher precedence than −o. All the operators and flags are separate arguments to test. Parentheses are meaningful to the Shell; thus, they must be escaped.