Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ test(C) — OpenDesktop 2.0.0a

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

find(C)

sh(C)


 test(C)                         19 June 1992                         test(C)


 Name

    test - test conditions

 Syntax

    test expr

    [ expr ]

 Description

    The test command evaluates the expression expr, and if its value is true,
    returns a zero (true) exit status; otherwise, test returns a non-zero
    exit status if there are no arguments.  The following primitives are used
    to construct expr:

    -r file   True if file exists and is readable.

    -w file   True if file exists and is writable.

    -x file   True if file exists and is executable.

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

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

    -h file   True if file exists and is a symbolic link.  With all other
              primitives (except -L file), the symbolic links are followed.
              This primitive is identical to -L.

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

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

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

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

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

    -s file   True if file 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.

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

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

    -L file   True if file exists and is a symbolic link.  With all other
              primitives (except -h file), the symbolic links are followed by
              default. This primitive is identical to -h.

    s1=s2     True if strings s1 and s2 are identical.

    s1!=s2    True if strings s1 and s2 are not identical.

    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, and -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  (-a has higher precedence than -o)

    (expr)    Parentheses for grouping

    Notice that all the operators and flags are separate arguments to test.
    Notice also, that parentheses are meaningful to the shell and, therefore,
    must be escaped.

 Note

    A version of test is built into sh(C) and ksh(C).  For details, refer to
    the appropriate section.

 See also

    find(C), sh(C)

 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.

 Standards conformance

    test is conformant with:

    AT&T SVID Issue 2;
    and X/Open Portability Guide, Issue 3, 1989.


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