aboutsummaryrefslogtreecommitdiff
path: root/man/man1/test.html
blob: 0f3fa85dbed648ef9094c861cdebb6d94ee207a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<head>
<title>test(1) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>TEST(1)</b><td align=right><b>TEST(1)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    test &ndash; set status according to condition<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>test</font></tt> <i>expr<br>
    </i>
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Test</i> evaluates the expression <i>expr</i>. If the value is true the exit
    status is null; otherwise the exit status is non-null. If there
    are no arguments the exit status is non-null. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The following primitives are used to construct <i>expr</i>.<br>
    <tt><font size=+1>&#8722;r</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists (is accessible) and is readable.<br>
    <tt><font size=+1>&#8722;w</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and is writable.<br>
    <tt><font size=+1>&#8722;x</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and has execute permission.<br>
    <tt><font size=+1>&#8722;e</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists.<br>
    <tt><font size=+1>&#8722;f</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and is a plain file.<br>
    <tt><font size=+1>&#8722;d</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and is a directory.<br>
    <tt><font size=+1>&#8722;s</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and has a size greater than zero.<br>
    <tt><font size=+1>&#8722;t</font></tt> <i>fildes</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the open file whose file descriptor number is
    <i>fildes</i> (1 by default) is the same file as <tt><font size=+1>/dev/cons</font></tt>.<br>
    <tt><font size=+1>&#8722;A</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and is append-only.<br>
    <tt><font size=+1>&#8722;L</font></tt> <i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and is exclusive-use.<br>
    <tt><font size=+1>&#8722;T</font></tt><i>file</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the file exists and is temporary.<br>
    <i>s1</i> <tt><font size=+1>=</font></tt> <i>s2</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the strings <i>s1</i> and <i>s2</i> are identical.<br>
    <i>s1</i> <tt><font size=+1>!=</font></tt> <i>s2</i>&nbsp;&nbsp;&nbsp;&nbsp;True if the strings <i>s1</i> and <i>s2</i> are not identical.<br>
    s1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if <i>s1</i> is not the null string. (Deprecated.)<br>
    <tt><font size=+1>&#8722;n</font></tt> <i>s1</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the length of string <i>s1</i> is non-zero.<br>
    <tt><font size=+1>&#8722;z</font></tt> <i>s1</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True if the length of string <i>s1</i> is zero.<br>
    <i>n1</i> <tt><font size=+1>&#8722;eq</font></tt> <i>n2</i>True if the integers <i>n1</i> and <i>n2</i> are arithmetically equal.
    Any of the comparisons <tt><font size=+1>&#8722;ne</font></tt>, <tt><font size=+1>&#8722;gt</font></tt>, <tt><font size=+1>&#8722;ge</font></tt>, <tt><font size=+1>&#8722;lt</font></tt>, or <tt><font size=+1>&#8722;le</font></tt> may be used
    in place of <tt><font size=+1>&#8722;eq</font></tt>. The (nonstandard) construct <tt><font size=+1>&#8722;l</font></tt> <i>string</i>, meaning
    the length of <i>string</i>, may be used in place of an integer.<br>
    <i>a</i> <tt><font size=+1>&#8722;nt</font></tt> <i>b</i>&nbsp;&nbsp;&nbsp;&nbsp;True if file <i>a</i> is newer than (modified after) file <i>b</i>.<br>
    <i>a</i> <tt><font size=+1>&#8722;ot</font></tt> <i>b</i>&nbsp;&nbsp;&nbsp;&nbsp;True if file <i>a</i> is older than (modified before) file <i>b</i>.<br>
    <i>f</i> <tt><font size=+1>&#8722;older</font></tt> <i>t</i>True if file <i>f</i> is older than (modified before) time
    <i>t</i>. If <i>t</i> is a integer followed by the letters <tt><font size=+1>y</font></tt>(years), <tt><font size=+1>M</font></tt>(months),
    <tt><font size=+1>d</font></tt>(days), <tt><font size=+1>h</font></tt>(hours), <tt><font size=+1>m</font></tt>(minutes), or <tt><font size=+1>s</font></tt>(seconds), it represents current
    time minus the specified time. If there is no letter, it represents
    seconds since epoch. You can also concatenate mixed units.
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            For example, <tt><font size=+1>3d12h</font></tt> means three days and twelve hours ago. 
            <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
            
            
        </table>
        
    </table>
    These primaries may be combined with the following operators:<br>
    <tt><font size=+1>!</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unary negation operator<br>
    <tt><font size=+1>&#8722;o</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binary <i>or</i> operator<br>
    <tt><font size=+1>&#8722;a</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binary <i>and</i> operator; higher precedence than <tt><font size=+1>&#8722;o<br>
    (</font></tt> <i>expr</i> <tt><font size=+1>)</font></tt>&nbsp;&nbsp;&nbsp;parentheses for grouping. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The primitives <tt><font size=+1>&#8722;b</font></tt>, <tt><font size=+1>&#8722;u</font></tt>, <tt><font size=+1>&#8722;g</font></tt>, and <tt><font size=+1>&#8722;s</font></tt> return false; they are recognized
    for compatibility with POSIX. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    Notice that all the operators and flags are separate arguments
    to <i>test</i>. Notice also that parentheses and equal signs are meaningful
    to <i>rc</i> and must be enclosed in quotes.<br>
    
</table>
<p><font size=+1><b>EXAMPLES     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Test</i> is a dubious way to check for specific character strings:
    it uses a process to do what an <a href="../man1/rc.html"><i>rc</i>(1)</a> match or switch statement
    can do. The first example is not only inefficient but wrong, because
    <i>test</i> understands the purported string <tt><font size=+1>&quot;&#8722;c&quot;</font></tt> as an option.<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>if (test $1 '=' &quot;&#8722;c&quot;) echo OK # wrong!<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    A better way is<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>if (~ $1 &#8722;c) echo OK<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    Test whether <tt><font size=+1>abc</font></tt> is in the current directory.<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>test &#8722;f abc &#8722;o &#8722;d abc<br>
        </font></tt>
    </table>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/cmd/test.c<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man1/rc.html"><i>rc</i>(1)</a><br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>