Tests the expression given and sets the exit status to 0 if true, and 1 if false. An expression is made up of one or more operators and their arguments.
The first form (`test`) is preferred. For compatibility with other shells, the second form is available: a matching pair of square brackets (`[ [EXPRESSION ] ]`).
This test is mostly POSIX-compatible.
When using a variable as an argument for a test operator you should almost always enclose it in double-quotes. There are only two situations it is safe to omit the quote marks. The first is when the argument is a literal string with no whitespace or other characters special to the shell (e.g., semicolon). For example, `test -b /my/file`. The second is using a variable that expands to exactly one element including if that element is the empty string (e.g., `set x ''`). If the variable is not set, set but with no value, or set to more than one value you must enclose it in double-quotes. For example, `test "$x" = "$y"`. Since it is always safe to enclose variables in double-quotes when used as `test` arguments that is the recommended practice.
-`-b FILE` returns true if `FILE` is a block device.
-`-c FILE` returns true if `FILE` is a character device.
-`-d FILE` returns true if `FILE` is a directory.
-`-e FILE` returns true if `FILE` exists.
-`-f FILE` returns true if `FILE` is a regular file.
-`-g FILE` returns true if `FILE` has the set-group-ID bit set.
-`-G FILE` returns true if `FILE` exists and has the same group ID as the current user.
-`-k FILE` returns true if `FILE` has the sticky bit set. If the OS does not support the concept it returns false. See https://en.wikipedia.org/wiki/Sticky_bit.
-`-L FILE` returns true if `FILE` is a symbolic link.
-`-O FILE` returns true if `FILE` exists and is owned by the current user.
-`-p FILE` returns true if `FILE` is a named pipe.
-`-r FILE` returns true if `FILE` is marked as readable.
-`-s FILE` returns true if the size of `FILE` is greater than zero.
-`-S FILE` returns true if `FILE` is a socket.
-`-t FD` returns true if the file descriptor `FD` is a terminal (TTY).
-`-u FILE` returns true if `FILE` has the set-user-ID bit set.
-`-w FILE` returns true if `FILE` is marked as writable; note that this does not check if the filesystem is read-only.
-`-x FILE` returns true if `FILE` is marked as executable.
If the variable `MANPATH` is defined and not empty, print the contents. (If `MANPATH` is not defined, then it will expand to zero arguments, unless quoted.)
Parentheses and the `-o` and `-a` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a `/foo` or `/bar` file as well as a `/baz` or `/bat` file.
`test` implements a subset of the <a href="http://www.unix.com/man-page/POSIX/1/test/">IEEE Std 1003.1-2008 (POSIX.1) standard</a>. The following exceptions apply:
- The `<` and `>` operators for comparing strings are not implemented.
- Because this test is a shell builtin and not a standalone utility, using the -c flag on a special file descriptors like standard input and output may not return the same result when invoked from within a pipe as one would expect when invoking the `test` utility in another shell.
In cases such as this, one can use `command``test` to explicitly use the system's standalone `test` rather than this `builtin``test`.