| <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 – 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>−r</font></tt> <i>file</i> True if the file exists (is accessible) and is readable.<br> |
| <tt><font size=+1>−w</font></tt> <i>file</i> True if the file exists and is writable.<br> |
| <tt><font size=+1>−x</font></tt> <i>file</i> True if the file exists and has execute permission.<br> |
| <tt><font size=+1>−e</font></tt> <i>file</i> True if the file exists.<br> |
| <tt><font size=+1>−f</font></tt> <i>file</i> True if the file exists and is a plain file.<br> |
| <tt><font size=+1>−d</font></tt> <i>file</i> True if the file exists and is a directory.<br> |
| <tt><font size=+1>−s</font></tt> <i>file</i> True if the file exists and has a size greater than zero.<br> |
| <tt><font size=+1>−t</font></tt> <i>fildes</i> 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>−A</font></tt> <i>file</i> True if the file exists and is append-only.<br> |
| <tt><font size=+1>−L</font></tt> <i>file</i> True if the file exists and is exclusive-use.<br> |
| <tt><font size=+1>−T</font></tt><i>file</i> True if the file exists and is temporary.<br> |
| <i>s1</i> <tt><font size=+1>=</font></tt> <i>s2</i> 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> True if the strings <i>s1</i> and <i>s2</i> are not identical.<br> |
| s1 True if <i>s1</i> is not the null string. (Deprecated.)<br> |
| <tt><font size=+1>−n</font></tt> <i>s1</i> True if the length of string <i>s1</i> is non-zero.<br> |
| <tt><font size=+1>−z</font></tt> <i>s1</i> True if the length of string <i>s1</i> is zero.<br> |
| <i>n1</i> <tt><font size=+1>−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>−ne</font></tt>, <tt><font size=+1>−gt</font></tt>, <tt><font size=+1>−ge</font></tt>, <tt><font size=+1>−lt</font></tt>, or <tt><font size=+1>−le</font></tt> may be used |
| in place of <tt><font size=+1>−eq</font></tt>. The (nonstandard) construct <tt><font size=+1>−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>−nt</font></tt> <i>b</i> True if file <i>a</i> is newer than (modified after) file <i>b</i>.<br> |
| <i>a</i> <tt><font size=+1>−ot</font></tt> <i>b</i> True if file <i>a</i> is older than (modified before) file <i>b</i>.<br> |
| <i>f</i> <tt><font size=+1>−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> unary negation operator<br> |
| <tt><font size=+1>−o</font></tt> binary <i>or</i> operator<br> |
| <tt><font size=+1>−a</font></tt> binary <i>and</i> operator; higher precedence than <tt><font size=+1>−o<br> |
| (</font></tt> <i>expr</i> <tt><font size=+1>)</font></tt> parentheses for grouping. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| The primitives <tt><font size=+1>−b</font></tt>, <tt><font size=+1>−u</font></tt>, <tt><font size=+1>−g</font></tt>, and <tt><font size=+1>−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>"−c"</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 '=' "−c") 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 −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 −f abc −o −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> |