DOKK / manpages / debian 10 / 9base / test.1plan9.en
TEST(1plan9) TEST(1plan9)

test - set status according to condition

test expr

Test evaluates the expression expr. 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.

The following primitives are used to construct expr.

True if the file exists (is accessible) and is readable.
True if the file exists and is writable.
True if the file exists and has execute permission.
True if the file exists.
True if the file exists and is a plain file.
True if the file exists and is a directory.
True if the file exists and has a size greater than zero.
True if the open file whose file descriptor number is fildes (1 by default) is the same file as /dev/cons.
True if the file exists and is append-only.
True if the file exists and is exclusive-use.
True if the file exists and is temporary.
True if the strings s1 and s2 are identical.
True if the strings s1 and s2 are not identical.
True if s1 is not the null string. (Deprecated.)
True if the length of string s1 is non-zero.
True if the length of string s1 is zero.
True if the integers n1 and n2 are arithmetically equal. Any of the comparisons -ne, -gt, -ge, -lt, or -le may be used in place of -eq. The (nonstandard) construct -l string, meaning the length of string, may be used in place of an integer.
True if file a is newer than (modified after) file b.
True if file a is older than (modified before) file b.
True if file f is older than (modified before) time t. If t is a integer followed by the letters y(years), M(months), d(days), h(hours), m(minutes), or s(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. For example, 3d12h means three days and twelve hours ago.

These primaries may be combined with the following operators:

!
unary negation operator
binary or operator
binary and operator; higher precedence than -o
( expr )
parentheses for grouping.

The primitives -b, -u, -g, and -s return false; they are recognized for compatibility with POSIX.

Notice that all the operators and flags are separate arguments to test. Notice also that parentheses and equal signs are meaningful to rc and must be enclosed in quotes.

Test is a dubious way to check for specific character strings: it uses a process to do what an rc(1) match or switch statement can do. The first example is not only inefficient but wrong, because test understands the purported string "-c" as an option.

if (test $1 '=' "-c") echo OK	# wrong!
    

A better way is

if (~ $1 -c) echo OK
    

Test whether is in the current directory.

test -f abc -o -d abc

/src/cmd/test.c

rc(1)