TEST(1) BSD Reference Manual TEST(1)
t
\bte
\bes
\bst
\bt - condition evaluation utility
S
\bSY
\bYN
\bNO
\bOP
\bPS
\bSI
\bIS
\bS
t
\bte
\bes
\bst
\bt _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn
D
\bDE
\bES
\bSC
\bCR
\bRI
\bIP
\bPT
\bTI
\bIO
\bON
\bN
The t
\bte
\bes
\bst
\bt utility evaluates the expression and, if it evaluates to true,
returns a zero (true) exit status; otherwise it returns 1 (false). If
there is no expression, test also returns 1 (false).
All operators and flags are separate arguments to the t
\bte
\bes
\bst
\bt utility.
The following primaries are used to construct expression:
-
\b-b
\bb _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is a block special file.
-
\b-c
\bc _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is a character special file.
-
\b-d
\bd _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is a directory.
-
\b-e
\be _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists (regardless of type).
-
\b-f
\bf _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is a regular file.
-
\b-g
\bg _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and its set group ID flag is set.
-
\b-h
\bh _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is a symbolic link.
-
\b-n
\bn _
\bs_
\bt_
\br_
\bi_
\bn_
\bg True if the length of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg is nonzero.
-
\b-p
\bp _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be is a named pipe (FIFO).
-
\b-r
\br _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be _
\be_
\bx_
\bi_
\bs_
\bt_
\bs _
\ba_
\bn_
\bd _
\bi_
\bs _
\br_
\be_
\ba_
\bd_
\ba_
\bb_
\bl_
\be_
\b.
-
\b-s
\bs _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and has a size greater than zero.
-
\b-t
\bt _
\b[_
\bf_
\bi_
\bl_
\be_
\b__
\bd_
\be_
\bs_
\bc_
\br_
\bi_
\bp_
\bt_
\bo_
\br_
\b]
True if the file whose file descriptor number is
_
\bf_
\bi_
\bl_
\be_
\b__
\bd_
\be_
\bs_
\bc_
\br_
\bi_
\bp_
\bt_
\bo_
\br (default 1) is open and is associated with
-
\b-u
\bu _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and its set user ID flag is set.
-
\b-w
\bw _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is writable. True indicates only
that the write flag is on. The file is not writable on a
read-only file system even if this test indicates true.
-
\b-x
\bx _
\bf_
\bi_
\bl_
\be True if _
\bf_
\bi_
\bl_
\be exists and is executable. True indicates only
that the execute flag is on. If _
\bf_
\bi_
\bl_
\be is a directory, true
indicates that _
\bf_
\bi_
\bl_
\be can be searched.
-
\b-z
\bz _
\bs_
\bt_
\br_
\bi_
\bn_
\bg True if the length of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg is zero.
_
\bs_
\bt_
\br_
\bi_
\bn_
\bg True if _
\bs_
\bt_
\br_
\bi_
\bn_
\bg is not the null string.
_
\bs_
\b1 =
\b= _
\bs_
\b2 True if the strings _
\bs_
\b1 and _
\bs_
\b2 are identical.
_
\bs_
\b1 !
\b!=
\b= _
\bs_
\b2 True if the strings _
\bs_
\b1 and _
\bs_
\b2 are not identical.
_
\bn_
\b1 -
\b-e
\beq
\bq _
\bn_
\b2 True if the integers _
\bn_
\b1 and _
\bn_
\b2 are algebraically equal.
_
\bn_
\b1 -
\b-n
\bne
\be _
\bn_
\b2 True if the integers _
\bn_
\b1 and _
\bn_
\b2 are not algebraically equal.
_
\bn_
\b1 -
\b-g
\bgt
\bt _
\bn_
\b2 True if the integer _
\bn_
\b1 is algebraically greater than the
_
\bn_
\b1 -
\b-g
\bge
\be _
\bn_
\b2 True if the integer _
\bn_
\b1 is algebraically greater than or
equal to the integer _
\bn_
\b2.
_
\bn_
\b1 -
\b-l
\blt
\bt _
\bn_
\b2 True if the integer _
\bn_
\b1 is algebraically less than the inte-
_
\bn_
\b1 -
\b-l
\ble
\be _
\bn_
\b2 True if the integer _
\bn_
\b1 is algebraically less than or equal
These primaries can be combined with the following operators:
!
\b! _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn True if _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn is false.
_
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b1 -
\b-a
\ba _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b2
True if both _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b1 and _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b2 are true.
_
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b1 -
\b-o
\bo _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b2
True if either _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b1 or _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn_
\b2 are true.
(
\b(_
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn)
\b) True if expression is true.
The -
\b-a
\ba operator has higher precedence than the -
\b-o
\bo operator.
G
\bGR
\bRA
\bAM
\bMM
\bMA
\bAR
\bR A
\bAM
\bMB
\bBI
\bIG
\bGU
\bUI
\bIT
\bTY
\bY
The t
\bte
\bes
\bst
\bt grammar is inherently ambiguous. In order to assure a degree of
consistency, the cases described in the IEEE Std1003.2 (``POSIX''), sec-
tion D11.2/4.62.4, standard are evaluated consistently according to the
rules specified in the standards document. All other cases are subject
to the ambiguity in the command semantics.
R
\bRE
\bET
\bTU
\bUR
\bRN
\bN V
\bVA
\bAL
\bLU
\bUE
\bES
\bS
The t
\bte
\bes
\bst
\bt utility exits with one of the following values:
0 expression evaluated to true.
1 expression evaluated to false or expression was missing.
S
\bST
\bTA
\bAN
\bND
\bDA
\bAR
\bRD
\bDS
\bS
The t
\bte
\bes
\bst
\bt function is expected to be IEEE Std1003.2 (``POSIX'') compati-