unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Page:
Section:
Apropos / Subsearch:
optional field

TEST(1V)                                                              TEST(1V)



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

SYNOPSIS
       test expression

       [ expression ]

DESCRIPTION
       test  evaluates  the  expression  expression 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 argu-
       ments.

USAGE
   Primitives
       The following primitives are used to construct expression.

       -b filename
                True if filename exists and is a block special device.

       -c filename
                True if filename exists and is a character special device.

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

       -f filename
                True if filename exists and is not a directory.

       -g filename
                True if filename exists and its set-group-ID bit is set.

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

       -k filename
                True if filename exists and its sticky bit is set.

       -l string
                the length of the string.

       -n s1    True if the length of the string s1 is non-zero.

       -p filename
                True if filename exists and is a named pipe (FIFO).

       -r filename
                True if filename exists and is readable.

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

       -t [ fildes ]
                True if the open file whose file descriptor number  is  fildes
                (1 by default) is associated with a terminal device.

       -u filename
                True if filename exists and its set-user-ID bit is set.

       -w filename
                True if filename exists and is writable.

       -x filename
                True if filename exists and is executable.

       -z s1    True if the length of string s1 is zero.

       s1 = s2  True if the strings s1 and s2 are equal.

       s1 != s2 True if the strings s1 and s2 are not equal.

       s1       True if s1 is not the null string.

       n1 -eq n2
                True if the integers n1 and n2 are numerically equal.

       n1 -ne n2
                True if the integer n1 is not numerically equal to the integer
                n2.

       n1 -gt n2
                True if the integer n1 is numerically greater than the integer
                n2.

       n1 -ge n2
                True if the integer n1 is numerically greater than or equal to
                the integer n2.

       n1 -lt n2
                True if the integer n1 is numerically less  than  the  integer
                n2.

       n1 -le n2
                True  if  the  integer n1 is numerically less than or equal to
                the integer n2.

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

              !      Unary negation operator.

              -a     Binary and operator.

              -o     Binary or operator.

              (expression)
                     Parentheses for grouping.

       -a has higher precedence than -o.  Notice that all  the  operators  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 filename True if filename exists and is a regular file.

       -l string   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,  depending  on  whether  /usr/5bin
       appears  before /usr/bin in the shell's PATH variable.  This is consis-
       tent 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 pathname; if the  program
       is in the current directory, ./test will suffice.





                               15 December 1988                       TEST(1V)