

test                         Command                         test




Evaluate conditional expression

tteesstt _e_x_p_r_e_s_s_i_o_n ...

tteesstt   evaluates  an   _e_x_p_r_e_s_s_i_o_n,  which   consists   of  string
comparisons, numerical comparisons, and tests of file attributes.
For example, a tteesstt command  might be used within a shell command
file to test whether a  certain file exists and is readable.  The
logical result  (true or false) of the  _e_x_p_r_e_s_s_i_o_n is returned by
the command, for use by a shell construct such as iiff.

_e_x_p_r_e_s_s_i_o_n is constructed  from the following elements, which are
true if the given condition holds and false if not:

_e_x_p_1 -aa _e_x_p_2
          Both expressions _e_x_p_1 and _e_x_p_2 are true.

-bb _f_i_l_e   _f_i_l_e is a block-special device.  kksshh only.

-cc _f_i_l_e   _f_i_l_e is a character-special file.  kksshh only.

-dd _f_i_l_e   _f_i_l_e exists and is a directory.

_f_i_l_e_1 -eeff _f_i_l_e_2
          _f_i_l_e_1 is the same file as _f_i_l_e_2. kksshh only.

_n_1 -eeqq _n_2 Numbers _n_1 and _n_2 are equal.

-ff _f_i_l_e   _f_i_l_e exists and is not a directory.

-gg _f_i_l_e   File mode has sseettggiidd bit.  kksshh only.

_n_1 -ggee _n_2 Number _n_1 is greater than or equal to _n_2.

_n_1 -ggtt _n_2 Number _n_1 is greater than _n_2.

-kk _f_i_l_e   File mode has sticky bit.  kksshh only.

-LL _f_i_l_e   File is a symbolic link.  kksshh only.

_n_1 -llee _n_2 Number _n_1 is less than or equal to _n_2.

_n_1 -lltt _n_2 Number _n_1 is less than _n_2.

-nn _s_t_r_i_n_g _s_t_r_i_n_g has nonzero length.

_n_1 -nnee _n_2 Numbers _n_1 and _n_2 are not equal.

_f_i_l_e_1 -nntt _f_i_l_e_2
          _f_i_l_e_1 is newer than kksshh only.

_e_x_p_1 -oo _e_x_p_2
          Either expression _e_x_p_1 or _e_x_p_2 is true.  -aa has greater
          precedence than -oo.


COHERENT Lexicon                                           Page 1




test                         Command                         test




_f_i_l_e_1 -oott _f_i_l_e_2
          _f_i_l_e_1 is older than _f_i_l_e_2. kksshh only.

-pp _f_i_l_e   _f_i_l_e is a named pipe.  kksshh only.

-rr _f_i_l_e   _f_i_l_e exists and is readable.

-ss _f_i_l_e   _f_i_l_e exists and has nonzero size.

-tt [_f_d]   _f_d is  the file  descriptor number  of a file  which is
          open and a terminal.  If no _f_d is given, it defaults to
          the standard output (file descriptor 1).

-uu _f_i_l_e   File mode has sseettuuiidd set.  kksshh only.

-ww _f_i_l_e   _f_i_l_e exists and is writable.

-xx _f_i_l_e   _f_i_l_e exists and executable.  kksshh only.

-zz _s_t_r_i_n_g _s_t_r_i_n_g has zero length (is a null string).

_s_t_r_i_n_g    _s_t_r_i_n_g has nonzero length.

_s_t_r_i_n_g_1 = _s_t_r_i_n_g_2
          _s_t_r_i_n_g_1 is equal to _s_t_r_i_n_g_2.

! _e_x_p     Negates the logical value of expression _e_x_p.

_s_t_r_i_n_g_1 != _s_t_r_i_n_g_2
          _s_t_r_i_n_g_1 is not equal to _s_t_r_i_n_g_2.

(_e_x_p)     Parentheses allow expression grouping.

***** Example *****

The following example  uses the tteesstt command to determine whether
a file is writable.


if test ! -w /dev/lp
then
        echo The line printer is inaccessible.
fi


Under COHERENT, the command `['  is linked to tteesstt. If invoked as
`[', tteesstt  checks that its last argument is  `]'.  This allows an
alternative syntax: simply enclose _e_x_p_r_e_s_s_i_o_n in square brackets.
For example, the above example can be written as follows:







COHERENT Lexicon                                           Page 2




test                         Command                         test



if [ ! -w /dev/lp ]
then
        echo The line printer is inaccessible.
fi


For a more extended example of the square-bracket syntax, see sshh.

***** See Also *****

ccoommmmaannddss, eexxpprr, ffiinndd, iiff, kksshh, sshh, wwhhiillee

***** Notes *****

The Korn shell's version of  this command is based on the public-
domain version written by Erik Baalbergen and Arnold Robbins.









































COHERENT Lexicon                                           Page 3


