test
Return true or false by performing tests (POSIX, toybox)
Syntax:
test [-bcdefghLPrSsuwx path] [-nz string] [-t fd] [arg1 operator arg2]
Runs on:
QNX OS
Options:
Tests with one argument
- -b path
- Test if path blocks device.
- -c path
- Test if path is a char device.
- -d path
- Test if path is a directory.
- -e path
- Test if path exists.
- -f path
- Test if path is a regular file.
- -g path
- Test if path is a setgid (set group ID).
- -h path
- Test if path is a symlink.
- -k path
- Test if path has a sticky bit.
- -L path
- Test if path is a symlink.
- -n string
- Test if the string size is non-zero .
- -p path
- Test if path is FIFO.
- -r path
- Test if path is readable.
- -S path
- Test if path is a socket.
- -s path
- Test if path size is non-zero.
- -t fd
- Test if file descriptor fd is a tty.
- -u path
- Test if path has a setuid bit.
- -w path
- Test if path is writable.
- -x path
- Test if path is executable.
- -z string
- Test if string size is zero.
Tests with two arguments
The following options are for tests with one argument on each side of the operator:
- =
- Test if strings are equal.
- !=
- Test if strings differ.
- =~
- Test if strings match regex.
- <
- Test if arg1 is lower than arg2 in an alpabetical sort.
- >
- Test if arg1 is greater than arg2 in an alpabetical sort.
- -eq
- Test if both integers are equal.
- -ge
- Test if first integer arg1 is greater than or equal to second integer arg2.
- -gt
- Test if first integer arg1 is greater than second integer arg2
- -le
- Test if first integer arg1 is less than or equal to second integer arg2.
- -lt
- Test if first integer arg1 is less than to second integer arg2.
- -ne
- Test if two integers are not equal.
Modifying or combining tests
The operators below can be used in combination with the expressions above to modify tests:
- ! expression
- Swap true or false (NOT operator).
- ( expression )
- Evaluate this test first.
- expression1 -a expression2
- Test if both expressions are true (AND operator).
- expression1 -o expression2
- Test if one or both expressions are true (OR operator).
Description:
The test utility returns true or false by performing tests. If there are no arguments or the argument contains an empty string, the test utility returns false.
This utility is provided as part of the toybox package. For information on how to enable it, see toybox.
Contributing author:
Rob Landley and the toybox project (see https://landley.net/toybox/).
Page updated: