Documentation
¶
Overview ¶
Package testcmd implements the POSIX test and [ builtin commands.
Usage:
test EXPRESSION [ EXPRESSION ]
Evaluate a conditional expression and exit with status 0 (true) or 1 (false). The [ form requires a closing ] as the last argument.
Exit codes:
0 — expression evaluates to true 1 — expression evaluates to false 2 — syntax/usage error
Supported operators:
File tests (unary):
-a FILE FILE exists (deprecated POSIX synonym for -e) -e FILE FILE exists -f FILE FILE exists and is a regular file -d FILE FILE exists and is a directory -s FILE FILE exists and has size greater than zero -r FILE FILE exists and is readable -w FILE FILE exists and is writable -x FILE FILE exists and is executable -h FILE FILE exists and is a symbolic link -L FILE FILE exists and is a symbolic link (same as -h) -p FILE FILE exists and is a named pipe (FIFO)
File comparison (binary):
FILE1 -nt FILE2 FILE1 is newer (modification time) than FILE2 FILE1 -ot FILE2 FILE1 is older (modification time) than FILE2
String tests (unary):
-z STRING length of STRING is zero -n STRING length of STRING is non-zero STRING STRING is non-empty (equivalent to -n STRING)
String comparison (binary):
S1 = S2 strings are equal S1 == S2 strings are equal (synonym for =) S1 != S2 strings are not equal S1 < S2 S1 sorts before S2 (lexicographic) S1 > S2 S1 sorts after S2 (lexicographic)
Integer comparison (binary):
N1 -eq N2 integers are equal N1 -ne N2 integers are not equal N1 -lt N2 N1 is less than N2 N1 -le N2 N1 is less than or equal to N2 N1 -gt N2 N1 is greater than N2 N1 -ge N2 N1 is greater than or equal to N2
Logical operators:
! EXPR EXPR is false EXPR1 -a EXPR2 both EXPR1 and EXPR2 are true EXPR1 -o EXPR2 either EXPR1 or EXPR2 is true ( EXPR ) grouping (parentheses must be shell-escaped)
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BracketCmd = builtins.Command{ Name: "[", Description: "evaluate conditional expression", MakeFlags: builtins.NoFlags(runBracket), }
BracketCmd is the "[" builtin command registration.
View Source
var Cmd = builtins.Command{ Name: "test", Description: "evaluate conditional expression", MakeFlags: builtins.NoFlags(runTest), }
Cmd is the "test" builtin command registration.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.