TEST(1B)
πΈ test (1B) β the BSD condition command, bestie edition π
ok so real talk: this page is /ucb/test, the BSD flavor, and it's literally the vibe check of the shell world. It looks at an expression and tells you if it's true or not. That's it. That's the whole job. Iconic, honestly. π
β¨ SYNOPSIS β¨
/ucb/test [expr]
π DESCRIPTION π
So test evaluates the expression expr, and here's the tea: if the expression's value is true, it bounces back with a zero exit status. If it's not true, you get a non zero exit status. π«Ά
And bestie, plot twist β test also returns a non zero exit if there are no arguments at all. Like, it needs something to work with, okay? π
The following primitives are the little building blocks you use to construct expr:
π¦ File primaries π¦
-r fileβ true if the file exists and is readable (you've got read permission, slay).-w fileβ true if the file exists and is writable (go off, write to it).-u fileβ true if the file exists and has the setuid bit set π-g fileβ true if the file exists and has the setgid bit set π-k fileβ true if the file exists and has the sticky bit set π-f fileβ true if the file exists and is not a directory.-d fileβ true if the file exists and is a directory π-h fileβ true if the file exists and is a symbolic link π-L fileβ true if the file exists and is a symbolic link π (yes, same energy as-h, both of them are valid, no cap)-p fileβ true if the file exists and is a named pipe π₯€-b fileβ true if the file exists and is a block device π-c fileβ true if the file exists and is a character device π-s fileβ true if the file exists and has a size greater than zero (it's got substance, we love that)
π§ Terminal primary π§
-t [fildes]β true if the open file whose file descriptor number is fildes β and yes, fildes is 1 by default β is associated with a terminal device. So like, are we talking to a real terminal or not? π
π String primaries π
-z s1β true if the length of string s1 is zero (empty string detected, nothing there π«₯).-n s1β true if the length of the string s1 is nonzero (there's content in there, periodt).s1 = s2β true if the strings s1 and s2 are equal πs1 != s2β true if the strings s1 and s2 are not equal πs1β true if s1 is not the null string (just the string by itself, standing there, being valid).
β Integer primary β
n1 -eq n2β true if the integers n1 and n2 are algebraically equal. And get this: any of the comparisons-ne,-gt,-ge,-lt, or-lemay be used in place of-eq. Mix and match, bestie, the whole squad's here π
π₯ OPERATORS π₯
These primaries may be combined with the following operators:
!β unary negation operator (the "actually, no" of the group chat) π-aβ binary and operator π-oβ binary or operator π( expr )β parentheses for grouping π
β οΈ ok important warning bestie:-ahas higher precedence than-o. So keep that in mind when you're stacking things up, or you'll get a result you did not manifest, fr fr. π
Also β huge one β notice that all the operators and flags are separate arguments to test. Like, they're not glued onto each other, each one is its own argument. And notice also that parentheses are meaningful as command separators and must be escaped. So if you just type them raw in a shell, they're gonna do shell things instead of test things. Escape them, bestie, please, for me π
π«Ά SEE ALSO π«Ά
Not gonna lie, this page doesn't list any SEE ALSO references β that's just how it is, no cap. The whole thing is self-contained, main character energy only π
okayyy that's the whole page, go forth and vibe check your file system π β¨
this lil gem comes from the Heirloom Toolchest, dated 7/2/05 β shoutout to the BSD System Compatibility crew for keeping it iconic π
π¦ where this page comes from
- nixos 26.05: heirloom 070715
- nixpkgs unstable: heirloom 070715
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms