


TEST(1V)                 USER COMMANDS                   TEST(1V)



NAME
     test - return true  or  false  according  to  a  conditional
     expression

SYNOPSIS
     test _e_x_p_r_e_s_s_i_o_n

     [ _e_x_p_r_e_s_s_i_o_n ]

DESCRIPTION
     test evaluates the expression _e_x_p_r_e_s_s_i_o_n and, if  its  value
     is  true,  returns  a  zero (true) exit status; otherwise, a
     non-zero (false) exit status is returned.   test  returns  a
     non-zero exit if there are no arguments.

USAGE
  Primitives
     The following primitives are used to construct _e_x_p_r_e_s_s_i_o_n.

     -b _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is a block special dev-
              ice.

     -c _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is a character  special
              device.

     -d _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is a directory.

     -f _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is not a directory.

     -g _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and its set-group-ID bit is
              set.

     -h _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is a symbolic link.

     -k _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and its sticky bit is set.

     -l _s_t_r_i_n_g
              the length of the string.

     -n _s_1    True if the length of the string _s_1 is non-zero.

     -p _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is a named pipe (FIFO).

     -r _f_i_l_e_n_a_m_e



Sun Release 4.1   Last change: 15 December 1988                 1






TEST(1V)                 USER COMMANDS                   TEST(1V)



              True if _f_i_l_e_n_a_m_e exists and is readable.

     -s _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and has a size greater than
              zero.

     -t [ _f_i_l_d_e_s ]
              True if the open file whose file descriptor  number
              is  _f_i_l_d_e_s (1 by default) is associated with a ter-
              minal device.

     -u _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and its set-user-ID bit  is
              set.

     -w _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is writable.

     -x _f_i_l_e_n_a_m_e
              True if _f_i_l_e_n_a_m_e exists and is executable.

     -z _s_1    True if the length of string _s_1 is zero.

     _s_1 = _s_2  True if the strings _s_1 and _s_2 are equal.

     _s_1 != _s_2 True if the strings _s_1 and _s_2 are not equal.

     _s_1       True if _s_1 is not the null string.

     _n_1 -eq _n_2
              True if the integers  _n_1  and  _n_2  are  numerically
              equal.

     _n_1 -ne _n_2
              True if the integer _n_1 is not numerically equal  to
              the integer _n_2.

     _n_1 -gt _n_2
              True if the integer _n_1 is numerically greater  than
              the integer _n_2.

     _n_1 -ge _n_2
              True if the integer _n_1 is numerically greater  than
              or equal to the integer _n_2.

     _n_1 -lt _n_2
              True if the integer _n_1 is numerically less than the
              integer _n_2.

     _n_1 -le _n_2
              True if the integer _n_1 is numerically less than  or




Sun Release 4.1   Last change: 15 December 1988                 2






TEST(1V)                 USER COMMANDS                   TEST(1V)



              equal to the integer _n_2.

  Operators
     The above primaries  may  be  combined  with  the  following
     operators:

          !    Unary negation operator.

          -a   Binary _a_n_d operator.

          -o   Binary _o_r operator.

          (_e_x_p_r_e_s_s_i_o_n)
               Parentheses for grouping.

     -a has higher precedence than -o. Notice that all the opera-
     tors  and flags are separate arguments to test.  Notice also
     that parentheses are meaningful to the  Shell  and  must  be
     escaped.

SYSTEM V USAGE
     The actions of the System V version of test  are  the  same,
     except for the following primitives:

     -f _f_i_l_e_n_a_m_e True if _f_i_l_e_n_a_m_e exists and is a regular file.

     -l _s_t_r_i_n_g   Not supported.

SEE ALSO
     find(1), sh(1)

WARNING
     In the second form of the command (that  is,  the  one  that
     uses  [],  rather  than  the word test), the square brackets
     must be delimited by blanks.

     Some UNIX systems do not recognize the second  form  of  the
     command.

NOTES
     The test command is  built  into  the  Bourne  shell,  which
     chooses the 4.2 BSD or the System V version of test, depend-
     ing on whether /usr/5bin  appears  before  /usr/bin  in  the
     shell's PATH variable.  This is consistent with the behavior
     of other commands present in both /usr/bin and /usr/5bin.

     The fact that test is built into the shell also means that a
     program  named test cannot be run without specifying a path-
     name; if the program is in  the  current  directory,  ./test
     will suffice.





Sun Release 4.1   Last change: 15 December 1988                 3






TEST(1V)                 USER COMMANDS                   TEST(1V)























































Sun Release 4.1   Last change: 15 December 1988                 4






