TEST(1plan9)
π NAME π
test β sets the exit status according to whether a condition is true or not, no cap π«Ά
β¨ SYNOPSIS β¨
test expr
π DESCRIPTION π
Okay so test evaluates the expression expr. If that value comes out true, the exit status is null (that's the good one, zero, the slay). Otherwise the exit status is non-null π
. And listen β if you pass it no arguments at all, the exit status is non-null. Empty-handed? Not the vibe. π
These are the primitives you build expr out of, bestie:
-r fileβ true if the file exists (like, is accessible) and you can read it π-w fileβ true if the file exists and you can write to it βοΈ-x fileβ true if the file exists and it has execute permission π-e fileβ true if the file exists, periodt-f fileβ true if the file exists and it's a plain file-d fileβ true if the file exists and it's a directory π-s fileβ true if the file exists and its size is greater than zero-t fildesβ true if the open file whose file descriptor number is fildes (1by default, bestie, that's stdout energy) is the same file as/dev/cons-A fileβ true if the file exists and it's append-only-L fileβ true if the file exists and it's exclusive-use-Tfileβ true if the file exists and it's temporarys1 = s2β true if the strings s1 and s2 are identical π―s1 != s2β true if the strings s1 and s2 are not identical πs1β true if s1 is not the null string. Deprecated, so likeβ¦ it's giving vintage, but pls move on π«-n s1β true if the length of string s1 is non-zero-z s1β true if the length of string s1 is zeron1 -eq n2β true if the integers n1 and n2 are arithmetically equal. Any of the comparisons-ne,-gt,-ge,-lt, or-lecan slide in where-eqwas. And the (nonstandard, iykyk) construct-l stringβ meaning the length of string β can be used in place of an integer β¨a -nt bβ true if file a is newer than (modified after) file b β°a -ot bβ true if file a is older than (modified before) file b π°οΈf -older tβ true if file f is older than (modified before) time t. If t is an integer followed by the lettersy(years),M(months),d(days),h(hours),m(minutes), ors(seconds), it represents current time minus the specified time. If there's no letter, it represents seconds since epoch. You can also concatenate mixed units, obsessed π. For example,3d12hmeans three days and twelve hours ago.
π Operators, the combiner era π
You can combine those primaries with these operators:
!β unary negation operator, the "actually no" π-oβ binary or operator-aβ binary and operator; it has higher precedence than-oπ( expr )β parentheses for grouping
Lowkey important: the primitives-b,-u,-g, and-sreturn false. They're only recognized for compatibility with POSIX. So if you were expecting them to do something cute β they're just standing there. π§
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. Yes fr fr, quote them. π«Ά
π¦ EXAMPLES π¦
Okay bestie, real talk: test is a dubious way to check for specific character strings β it spins up a whole process to do what an rc(1) match or switch statement can do with zero effort. The first example is not only inefficient but wrong, because test reads 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 abc is in the current directory:
test -f abc -o -d abc
π SOURCE π
/src/cmd/test.c
β SEE ALSO β
That's the whole page, bestie β this was TEST(1plan9), straight outta the 1plan9 manual, signed off in true TEST(1plan9) fashion. Go forth and exit status zero, my love π β¨π¦
π¦ where this page comes from
- debian bookworm: 9base 1:6-13 Β· Lucent
- debian trixie: 9base 1:6-14 Β· Lucent
- ubuntu jammy: 9base 1:6-11 Β· Lucent
- ubuntu noble: 9base 1:6-14 Β· Lucent
- ubuntu questing: 9base 1:6-15
- ubuntu resolute: 9base 1:6-15build1 Β· Lucent
- ubuntu stonking: 9base 1:6-15build1 Β· Lucent
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms