Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ test(1SH) — UTek W2.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

break(1sh)

cd(1sh)

chdir(1sh)

continue(1sh)

csh(1csh)

echo(1sh)

eval(1sh)

exec(1sh)

exit(1sh)

export(1sh)

expr(1)

find(1)

hash(1sh)

login(1)

make(1)

pwd(1sh)

read(1sh)

readonly(1sh)

return(1sh)

set(1sh)

sh(1sh)

shift(1sh)

test(1sh)

times(1sh)

trap(1sh)

type(1sh)

ulimit(1sh)

umask(1sh)

unset(1sh)

wait(1sh)

which(1sh)

access(2)

chmod(2)

execve(2)

stat(2)



TEST(1SH)               COMMAND REFERENCE               TEST(1SH)



NAME
     test - condition command (sh built-in)

SYNOPSIS
     test expr
     [ expr ]

DESCRIPTION
     Test evaluates the expression expr, and if its value is true
     then returns 0 exit status; otherwise, a nonzero exit status
     is returned.  Test returns a nonzero exit if there are no
     arguments.

     If test is executed as a bracket [, the last argument must
     be the matching bracket ].

     The command is available as a builtin sh command and as a
     shell script for use in csh and make.

     The following primitives are used to construct expr:

     -r filename
         True if the file exists and is readable.

     -w filename
         True if the file exists and is writable.

     -x filename
         True if the file exists and is executable.

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

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

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

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

     -U filename
         True if the file exists and is a UTek-domain socket.

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

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

     -k filename



Printed 10/17/86                                                1





TEST(1SH)               COMMAND REFERENCE               TEST(1SH)



         True if the file exists and its sticky bit is set (see
         chmod(2) ).

     -S filename
         True if the file exists and is a symbolic link.

     -s filename
         True if the file exists and has a size greater than 0.

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

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

     -n s1
         True if the length of the string s1 is nonzero.

     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 algebraically equal.
         Any of the comparisons -ne, -gt, -ge, -lt, or -le may be
         used in place of -eq.

     These primaries may be combined with the following
     operators:

     !   Unary negation operator

     -a  Binary and operator

     -o  Binary or operator

     ( expr )
         Parentheses for grouping

     There are four functions which return integer values and may
     only be used in algebraic comparisons:

     -l string
         Length of string

     -C filename



Printed 10/17/86                                                2





TEST(1SH)               COMMAND REFERENCE               TEST(1SH)



         Time of the last status change to filename (see stat(2))

     -M filename
         Time of the last modification to filename (see stat(2))

     -A filename
         Time of the last access to filename (see stat(2))

EXAMPLES
     The following example shows a piece of a shell script which
     prints a usage message if the first argument to the script
     is null:



          if test -z "$1"
          then
               echo "usage : script arg"
          fi


     The following shell script prints a message for each of its
     arguments that are longer than 72 characters:



          #!/bin/sh
          for i in "$@"
          do
               if [ -l $i -gt 72 ]
               then
                    echo "Argument too long :" $i
               fi
          done


     This example shows a use for the -M option. If the file copy
     is older than the file original, the latter is copied to
     copy:



          if test -M copy -lt -M original
          then
               cp original copy
          fi


RETURN VALUE
     [0]            The expression evaluates to true.

     [1]            The expression evaluates to false.



Printed 10/17/86                                                3





TEST(1SH)               COMMAND REFERENCE               TEST(1SH)



     [USAGE]        Incorrect command line syntax. Execution
                    terminated.

     [NP_ERR]       An error occurred that was not a system
                    error.  Execution terminated.

CAVEATS
     The -a option 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.

     The file access operators -r, -w, and -x always evaluate to
     false if the filename is null, as in the following example:



          test -r ""


     The builtin shell version of test does not print error
     message tags along with error messages.

SEE ALSO
     break(1sh), cd(1sh), chdir(1sh), continue(1sh), csh(1csh),
     echo(1sh), eval(1sh), exec(1sh), exit(1sh), export(1sh),
     expr(1), find(1), hash(1sh), login(1), make(1), pwd(1sh),
     read(1sh), readonly(1sh), return(1sh), set(1sh), sh(1sh),
     shift(1sh), test(1sh), times(1sh), trap(1sh), type(1sh),
     ulimit(1sh), umask(1sh), unset(1sh), wait(1sh), which(1sh),
     access(2), chmod(2), execve(2), stat(2).























Printed 10/17/86                                                4





































































%%index%%
na:72,78;
sy:150,139;
de:289,1783;2216,1741;4101,361;
ex:4462,906;
rv:5368,189;5701,205;
ca:5906,655;
se:6561,996;
%%index%%000000000148

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026