Annotation of researchv10dc/man/adm/man1/test.1, revision 1.1.1.1

1.1       root        1: .TH TEST 1
                      2: .CT 1 shell
                      3: .SH NAME
                      4: test, [, newer \- condition commands
                      5: .SH SYNOPSIS
                      6: .B test
                      7: .I expr
                      8: .PP
                      9: \fB[\fR
                     10: .I expr
                     11: \fB]\fR
                     12: .PP
                     13: .B newer
                     14: .I file1 file2
                     15: .SH DESCRIPTION
                     16: .I Test
                     17: evaluates the expression
                     18: .IR expr .
                     19: If the value is true the exit status is 0; otherwise the
                     20: exit status is nonzero.
                     21: If there are no arguments the exit status is nonzero.
                     22: .PP
                     23: The following primitives are used to construct
                     24: .IR expr .
                     25: .TP \w'\fL-t\fI\ fildes\ 'u
                     26: .BI -r " file"
                     27: True if the file exists (is accessible) and is readable.
                     28: .PD0
                     29: .TP
                     30: .BI -w " file"
                     31: True if the file exists and is writable.
                     32: .TP
                     33: .BI -x " file"
                     34: True if the file exists and has execute permission.
                     35: .TP
                     36: .BI -e " file
                     37: True if the file exists.
                     38: .TP
                     39: .BI -f " file"
                     40: True if the file exists and is a plain file.
                     41: .TP
                     42: .BI -d " file"
                     43: True if the file exists exists and is a directory.
                     44: .TP
                     45: .BI -c " file"
                     46: True if the file exists and is a character special file.
                     47: .TP
                     48: .BI -b " file"
                     49: True if the file exists and is a block special file.
                     50: .TP
                     51: .BI -L " file"
                     52: True if the file is a symbolic link.
                     53: .TP
                     54: .BI -u " file"
                     55: True if the file exists and has set userid permission.
                     56: .TP
                     57: .BI -g " file"
                     58: True if the file exists and has set groupid permission.
                     59: .TP
                     60: .BI -s " file"
                     61: True if the file exists and has a size greater than zero.
                     62: .TP
                     63: .BI -t " fildes
                     64: True if the open file whose file descriptor number is
                     65: .I fildes
                     66: (1 by default)
                     67: is associated with a terminal device.
                     68: .TP
                     69: .B -S
                     70: True if the effective userid is zero.
                     71: .TP
                     72: .IB s1 " = " s2
                     73: True
                     74: if the strings
                     75: .I s1
                     76: and
                     77: .I s2
                     78: are identical.
                     79: .TP
                     80: .IB s1 " != " s2
                     81: True
                     82: if the strings
                     83: .I s1
                     84: and
                     85: .I s2
                     86: are not identical.
                     87: .TP
                     88: s1
                     89: True if
                     90: .I s1
                     91: is not the null string.
                     92: (Deprecated.)
                     93: .TP
                     94: .BI -z " s1"
                     95: True if the length of string
                     96: .I s1
                     97: is zero.
                     98: .TP
                     99: .IB n1 " -eq " n2
                    100: True if the integers
                    101: .I n1
                    102: and
                    103: .I n2
                    104: are arithmetically equal.
                    105: Any of the comparisons
                    106: .BR -ne ,
                    107: .BR -gt ,
                    108: .BR -ge ,
                    109: .BR -lt ,
                    110: or
                    111: .BR -le
                    112: may be used in place of
                    113: .BR -eq .
                    114: The (nonstandard) construct
                    115: .BI -l " string,
                    116: meaning the length of
                    117: .I string,
                    118: may be used in place of an integer.
                    119: .PD
                    120: .PP
                    121: These primaries may be combined with the
                    122: following operators:
                    123: .TP
                    124: .B  !
                    125: unary negation operator
                    126: .PD0
                    127: .TP
                    128: .B  -o
                    129: binary
                    130: .I or
                    131: operator
                    132: .TP
                    133: .B  -a
                    134: binary
                    135: .I and
                    136: operator; higher precedence than
                    137: .BR -o
                    138: .TP
                    139: .BI "( " expr " )"
                    140: parentheses for grouping.
                    141: .PD
                    142: .PP
                    143: Notice that all the operators and flags are separate
                    144: arguments to
                    145: .IR test .
                    146: Notice also that parentheses are meaningful
                    147: to the Shell and must be escaped.
                    148: .PP
                    149: .B [
                    150: is a synonym for
                    151: .I test,
                    152: except that
                    153: .B [
                    154: requires a closing
                    155: .BR ] .
                    156: .PP
                    157: .I Newer
                    158: returns a zero exit code if
                    159: .I file1
                    160: exists and
                    161: .I file2
                    162: does not, or if
                    163: .I file1
                    164: and
                    165: .I file2
                    166: both exist and
                    167: .I file1
                    168: was modified at least as recently
                    169: as
                    170: .IR file2 .
                    171: It returns a non-zero return code otherwise.
                    172: .SH EXAMPLES
                    173: .I Test
                    174: is a dubious way to check for specific character strings:
                    175: it uses a process to do what a shell case statement can do.
                    176: The first example is not only inefficient but wrong, because
                    177: .I test
                    178: understands the purported string
                    179: .B  \&"-c"
                    180: as an option.
                    181: Furthermore
                    182: .B $1
                    183: might be empty.
                    184: .IP
                    185: .EX
                    186: if test $1 = "-c"      # wrong!
                    187: then echo OK
                    188: fi
                    189: .EE
                    190: .LP
                    191: A correct way is
                    192: .IP
                    193: .EX
                    194: case "$1" in
                    195: -c)    echo OK
                    196: esac
                    197: .EE
                    198: .PP
                    199: Test whether 
                    200: .L abc
                    201: is in the current directory.
                    202: .IP
                    203: .B test -e abc -o -L abc
                    204: .SH "SEE ALSO"
                    205: .IR sh (1), 
                    206: .IR find (1)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.