


TEST(1)             UNIX Programmer's Manual		  TEST(1)



NAME
     test - condition evaluation utility

SYNOPSIS
     test _e_x_p_r_e_s_s_i_o_n

DESCRIPTION
     The _t_e_s_t utility evaluates the expression and, if it evalu-
     ates 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_e_s_t
     utility.

     The following primaries are used to construct expression:

      -b   _f_i_l_e
	  True if _f_i_l_e exists and is a block special file.

      -c   _f_i_l_e
	  True if _f_i_l_e exists and is a character special file.

      -d   _f_i_l_e
	  True if _f_i_l_e exists and is a directory.

      -e   _f_i_l_e
	  True if _f_i_l_e exists (regardless of type).

      -f   _f_i_l_e
	  True if _f_i_l_e exists and is a regular file.

      -g   _f_i_l_e
	  True if _f_i_l_e exists and its set group ID flag is set.

      -h   _f_i_l_e
	  True if _f_i_l_e exists and is a symbolic link.

      -n   _s_t_r_i_n_g
	  True if the length of _s_t_r_i_n_g is nonzero.

      -p   _f_i_l_e
	  True if _f_i_l_e is a named pipe

      -r   _f_i_l_e
	  True if _f_i_l_e exists and is readable.

      -s   _f_i_l_e
	  True if _f_i_l_e exists and has a size greater than zero.

      -t   [_f_i_l_e__d_e_s_c_r_i_p_t_o_r]
	  True if the file whose file descriptor number is



Printed 11/24/99	 March 13, 1995                         1






TEST(1)             UNIX Programmer's Manual		  TEST(1)



	  _f_i_l_e__d_e_s_c_r_i_p_t_o_r (default 1) is open and is associated
	  with a terminal.

      -u   _f_i_l_e
	  True if _f_i_l_e exists and its set user ID flag is set.

      -w   _f_i_l_e
	  True if _f_i_l_e exists and is writable.	True indicates
	  only that the write flag is on.  The file is not writ-
	  able on a read-only file system even if this test indi-
	  cates true.

      -x   _f_i_l_e
	  True if _f_i_l_e exists and is executable.  True indicates
	  only that the execute flag is on.  If _f_i_l_e is a direc-
	  tory, true indicates that _f_i_l_e can be searched.

      -z   _s_t_r_i_n_g
	  True if the length of _s_t_r_i_n_g is zero.

      _s_t_r_i_n_g
	  True if _s_t_r_i_n_g is not the null string.

      _s_1   =   _s_2
	  True if the strings _s_1 and _s_2 are identical.

      _s_1   !=	_s_2
	  True if the strings _s_1 and _s_2 are not identical.

      _n_1   -eq	 _n_2
	  True if the integers _n_1 and _n_2 are algebraically equal.

      _n_1   -ne	 _n_2
	  True if the integers _n_1 and _n_2 are not algebraically
	  equal.

      _n_1   -gt	 _n_2
	  True if the integer _n_1 is algebraically greater than
	  the integer _n_2 .

      _n_1   -ge	 _n_2
	  True if the integer _n_1 is algebraically greater than or
	  equal to the integer _n_2 .

      _n_1   -lt	 _n_2
	  True if the integer _n_1 is algebraically less than the
	  integer _n_2 .

      _n_1   -le	 _n_2
	  True if the integer _n_1 is algebraically less than or
	  equal to the integer _n_2 .




Printed 11/24/99	 March 13, 1995                         2






TEST(1)             UNIX Programmer's Manual		  TEST(1)



	  These primaries can be combined with the following opera-
	  tors:


     ! expression
	  True if _e_x_p_r_e_s_s_i_o_n is false.

      _e_x_p_r_e_s_s_i_o_n_1   -a	 _e_x_p_r_e_s_s_i_o_n_2
	  True if both _e_x_p_r_e_s_s_i_o_n_1 and _e_x_p_r_e_s_s_i_o_n_2 are true.

      _e_x_p_r_e_s_s_i_o_n_1   -o	 _e_x_p_r_e_s_s_i_o_n_2
	  True if either _e_x_p_r_e_s_s_i_o_n_1 or _e_x_p_r_e_s_s_i_o_n_2 are true.

      (_e_x_p_r_e_s_s_i_o_n)
	  True if expression is true.

	  The
	  -a operator has higher precedence than the -o operator.

GRAMMAR AMBIGUITY
     The test grammar is inherently ambiguous.	In order to
     assure a degree of consistency, the cases described in the
     IEEE Std 1003.2 ("POSIX"), section 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.

RETURN VALUES
     The test utility exits with one of the following values:

     0	  expression evaluated to true.

     1	  expression evaluated to false or expression was miss-
	  ing.

     >1   An error occurred.

BUGS
     Named pipes are not implemented in 2.11BSD.

STANDARDS
     The test function is expected to be IEEE Std 1003.2
     ("POSIX") compatible.












Printed 11/24/99	 March 13, 1995                         3



