Check file types and compare values.
Synopsis
test EXPRESSION
[ EXPRESSION ]
Description
Evaluate EXPRESSION and exit with 0 (true) or 1 (false). Also available as [. Runs in the just-bash WASM shell inside SLICC.
File Tests
-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 a size greater than zero.
-r FILE FILE is readable.
-w FILE FILE is writable.
-x FILE FILE is executable.
String Tests
-z STRING STRING has zero length.
-n STRING STRING has non-zero length.
STRING1 = STRING2 Strings are equal.
STRING1 != STRING2 Strings are not equal.
Integer Comparisons
INT1 -eq INT2 Equal.
INT1 -ne INT2 Not equal.
INT1 -lt INT2 Less than.
INT1 -gt INT2 Greater than.
INT1 -le INT2 Less than or equal.
INT1 -ge INT2 Greater than or equal.
Logical Operators
! EXPRESSION Negate.
EXPR1 -a EXPR2 Both are true (AND).
EXPR1 -o EXPR2 Either is true (OR).
Examples
$ test -f file.txt && echo "exists"
Check if file exists.
$ [ "$a" = "$b" ] && echo "equal"
Compare two strings.
Notes
Built-in command of the just-bash WASM interpreter. File tests operate on the virtual filesystem.
See Also
if, case