tteesstt -- Command

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 script 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 another shell construct, such as the command iiff.

Under  the Korn  shell, tteesstt  is a  built-in command  that returns  zero if
_e_x_p_r_e_s_s_i_o_n is true,  and one if it is false.   Under the Bourne shell, tteesstt
is  not a  built-in  command; rather,  the  Bourne shell  uses the  command
/bbiinn/tteesstt to  test expressions.  /bbiinn/sshh returns zero  if the expression is
true,  one if  it is  false, and  two if  a syntax  error (or  other error)
occurred.

_E_x_p_r_e_s_s_i_o_n _O_p_t_i_o_n_s
tteesstt recognizes  the following options, one  or more of which  can be built
into an _e_x_p_r_e_s_s_i_o_n:

! _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.

_s_t_r_i_n_g_1 < _s_t_r_i_n_g_2
          _s_t_r_i_n_g_1 is lexicographically less than _s_t_r_i_n_g_2 (sshh only).

_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.

_s_t_r_i_n_g_1 > _s_t_r_i_n_g_2
          _s_t_r_i_n_g_1 is lexicographically greater than _s_t_r_i_n_g_2 (sshh only).

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

_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.

-cc _f_i_l_e   _f_i_l_e is a character-special file.

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

-ee _f_i_l_e   _f_i_l_e exists (/bbiinn/tteesstt only).

_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.

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

          Please note that tteesstt evalutes the expression  as zero.  Thus, if
          one of the  arguments is a variable that is  not set, tteesstt treats
          it as if it were zero.  For example, consider the expression:

              if [ "$notset" -eq 0 ]

          If nnoottsseett  is not set, tteesstt  evaluates it to zero  and so returns
          ttrruuee.

-ff _f_i_l_e   _f_i_l_e exists and is an ordinary file.

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

_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.

-LL _f_i_l_e   File is a symbolic link.

_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 _f_i_l_e_2.

_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.

_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.

-pp _f_i_l_e   _f_i_l_e is a named pipe.

-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 that is  open and a
          terminal.  The Bourne shell  requires that _f_d be given; under the
          Korn  shell,  however,  defaults  to  the standard  output  (file
          descriptor 1) if no _f_d is given.

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

-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.

-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.

_I_m_p_l_e_m_e_n_t_a_t_i_o_n_s _o_f _t_e_s_t
The implementation  of tteesstt under  the Bourne shell has  been rewritten for
COHERENT release 4.2,  both to extend its range of  features and to make it
more  compliant with  published standards.  Although  this makes  tteesstt more
useful to  programmers, it may  create problems when  you try to  execute a
Bourne-shell  script  written  under COHERENT  release  4.2  on an  earlier
release  of  COHERENT.   The following  describes  how  the Bourne  shell's
implementation of  tteesstt was designed; and how it  differs both from earlier
implementations under  the Bourne shell  and from the  implementation under
the Korn shell.

To begin, the Bourne shell's implementation of tteesstt attempts to comply with
the POSIX  Standard, comply  with previous  COHERENT releases of  tteesstt, and
comply with System-V UNIX  to the greatest extent possible.  However, these
objectives are  mutually exclusive.   See the POSIX  Standard P1003.2/D11.2
section  4.62,  especially  the  Rationale,  for  details of  some  of  the
problems.   In particular,  System V  and Berkeley differ  in the  way they
parse  some expressions,  which leads  the POSIX  Standard to  specify test
behavior for a minimal set of expressions, _n_o_t including -aa and -oo.

The  following details  differences  among the  various implementations  of
tteesstt.  First, the  following  options were  not implemented  in the  Bourne
shell's  implementation of  tteesstt prior  to COHERENT  release 4.2,  but were
included in the Korn shell's implementation:  -bb, -cc, -eeff, -gg, -kk, -LL, -nntt,
-oott, -pp, -uu, and -xx. Of these, the following are not described in the POSIX
Standard: -kk,  -LL, -eeff, -nntt,  and -oott. Note that  Bourne-shell scripts that
use any of  the above options to tteesstt will  _n_o_t run on versions of COHERENT
prior to release 4.2, but will run under the Korn shell.

Next, the  Bourne shell  for COHERENT  4.2 implements the  POSIX Standard's
option -ee  and the options  < and >.  Bourne-shell scripts that  use any of
these three options  to tteesstt will _n_o_t run on  versions of COHERENT prior to
release 4.2, nor will they run under the Korn shell.

The  definitions of  the  options -ff  and  -tt have  been  changed from  the
Berkeley  standard  to  that described  in  the  POSIX Standard.   Berkeley
defines -ff  as meaning that a  file exists and is  not a directory; whereas
the  POSIX Standard  defines it  as  meaning that  a file  exists and  is a
regular file.  Versions  of the Bourne shell prior to  COHERENT 4.2 use the
Berkeley  definitions; whereas  all version  of the  Korn shell  and Bourne
shell  under COHERENT  4.2 use the  POSIX Standard's  definition.  Berkeley
gives -tt a default value of one if it is not used with an argument; whereas
the POSIX Standard  requires that -tt have an argument.   The Korn shell and
all versions  of the Bourne  shell prior to  COHERENT 4.2 use  the Berkeley
definition;  whereas the  Bourne shell  under COHERENT  4.2 uses  the POSIX
Standard's definition.  These differences are subtle, but important.  Thus,
a  Bourne shell  script  that uses  either  of these  options  may not  run
correctly  when  imported  into  COHERENT  4.2  from  earlier  versions  of
COHERENT, or when exported from COHERENT 4.2 to them or to the Korn shell.

Finally, tteesstt  under the  Korn shell  and under the  Bourne shell  prior to
COHERENT 4.2  returns zero if an  expression is true and  one either if the
expression  is  false  or  if  the  expression contained  a  syntax  error.
However, tteesstt  under the Bourne shell  for COHERENT 4.2 returns  zero if an
expression is true, one if it is false, and two if a syntax error occurred.
Bourne-shell scripts that pay close  attention to what tteesstt returns may not
run correctly when  imported into COHERENT 4.2 from earlier implementations
of  COHERENT, or  when exported  from COHERENT 4.2  to earlier  versions of
COHERENT or to the Korn shell.

_E_x_a_m_p_l_e
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:

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.

_S_e_e _A_l_s_o
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

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