Using the test shell builtin
It is probably time for us to pull over to the side of the scripting highway and look a little more at this command test
. This is both a shell builtin and a file executable in its own right. Of course, we will have to hit the built-in command first, unless we specify the full path to the file.
When the test command is run without any expressions to evaluate, then the test will return false. So, if we run the test as shown in the following command:
$ test
The exit status will be 1
, even though no error output is shown. The test
command will always return either True
or False
or 0
or 1
, respectively. The basic syntax of test
is:
test EXPRESSION
Or, we can inverse the test
command with:
test ! EXPRESSION
If we need to include multiple expressions, these can be AND
or OR
together using the -a
and -o
options, respectively:
test EXPRESSION -a EXPRESSION test EXPRESSION -o EXPRESSION
We can also write in a shorthand version replacing the test with square brackets to surround...