TEST(1)
π NAME π
test β condition evaluation utility, hanging out in section 1 under the User Contributed Perl Documentation umbrella. Sheβs the bestie who checks a condition and tells you true or false through her exit status. No cap.
πΈ SYNOPSIS πΈ
test expression
[ expression ]
π¦ DESCRIPTION π¦
Okay so the test utility evaluates expression and, if it evaluates to true, returns a zero (true) exit status; otherwise it returns 1 (false). If no expression is given, test also returns 1 (false). Literally her whole personality.
All operators and flags are separate arguments to the test utility.
β¨ the primaries β¨
The following primaries are used to construct expression:
-bfile β true if file exists and is a block special file.-cfile β true if file exists and is a character special file.-dfile β true if file exists and is a directory.-efile β true if file exists (regardless of type).-ffile β true if file exists and is a regular file.-gfile β true if file exists and its set-group-ID flag is set.-hfile β true if file exists and is a symbolic link. This operator is for COMPATABILITY purposes, do not rely on its existence. Use-Linstead.-kfile β true if file exists and its sticky bit is set.-nstring β true if the length of string is nonzero.-pfile β true if file is a named pipe (FIFO).-rfile β true if file exists and is readable by the effective user/group.-sfile β true if file exists and has a size greater than zero.-tfile_descriptor β true if the file whose file descriptor number is file_descriptor is open and is associated with a terminal.-tβ same as above with an implicit file descriptor number of"1"(e.g.:-t 1).-ufile β true if file exists and its set-user-ID flag is set.-wfile β true if file exists and is writable by the effective user/group. True indicates only that the write flag is on. The file is not writable on a read-only file system even if this test indicates true.-xfile β true if file exists and is executable by the effective user/group. True indicates only that the execute flag is on. If file is a directory, true indicates that file can be searched.-zstring β true if the length of string is zero.-Bfile β true if file exists and is a binary file.-Lfile β true if file exists and is a symbolic link.-Ofile β true if file exists and its owner matches the effective user ID of this process.-Rfile β true if file exists and is readable by the real user/group.-Sfile β true if file exists and is a socket.-Tfile β true if file exists and is a text file.-Wfile β true if file exists and is writable by the real user/group. True indicates only that the write flag is on. The file is not writable on a read-only file system even if this test indicates true.-Xfile β true if file exists and is executable by the real user/group. True indicates only that the execute flag is on. If file is a directory, true indicates that file can be searched.file1 -nt file2β true if file1 exists and is newer than file2.file1 -ot file2β true if file1 exists and is older than file2.stringβ true if string is not the null string.s1 = s2β true if the strings s1 and s2 are identical.s1 != s2β true if the strings s1 and s2 are not identical.s1 < s2β true if string s1 comes before s2 based on the ASCII value of their characters.s1 > s2β true if string s1 comes after s2 based on the ASCII value of their characters.s1β true if s1 is not the null string.n1 -eq n2β true if the integers n1 and n2 are algebraically equal.n1 -ne n2β true if the integers n1 and n2 are not algebraically equal.n1 -gt n2β true if the integer n1 is algebraically greater than the integer n2.n1 -ge n2β true if the integer n1 is algebraically greater than or equal to the integer n2.n1 -lt n2β true if the integer n1 is algebraically less than the integer n2.n1 -le n2β true if the integer n1 is algebraically less than or equal to the integer n2.
π combining primaries: operators π
These primaries can be combined with the following operators:
! expressionβ true if expression is false.expression1 -a expression2β true if both expression1 and expression2 are true.expression1 -o expression2β true if either expression1 or expression2 are true.(expression)β true if expression is true (uses parentheses for grouping).
Note that the -a operator has higher precedence than the -o operator. Notice also that all the operators and flags are separate arguments to test.
π₯ RETURN VALUES π₯
The test utility exits with one of the following values:
$return_val == 0β expression evaluated to true.$return_val == 1β expression evaluated to false or expression was missing.$return_val > 1β an error occurred.
π CAVEATS π
β οΈ Bestie, command line arguments like parentheses and arithmetic operators (e.g.:'(',')','!','>','<', etc.) may be meaningful to the command-line interpreter (shell) and therefore may need to be escaped from any special shell interpretation. The shell is lowkey the main character here, so protect your args.
π«Ά SEE ALSO π«Ά
Go peek at sh and find, iykyk.
Mwah π β this page is from perl v5.42.2, dated 2026-02-15, and yes bestie itβs the TEST(1) manual. Periodt. π
π¦ where this page comes from
- alpine 3.24: perl-power-tools-doc 1.053-r1 Β· GPL-2.0-or-later AND Artistic-1.0-Perl AND Artistic-2.0 AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms