When scripting, you will probably want to be able to test whether a string is equal to another, or maybe check on a file status or even a numeric test. Based on the results of the test you can take further action. The test command can be used to test for strings, file status and numbers. It also fits in very well with the conditional if, then, else construct, as you’ll see in the next chapter.
In this chapter we will cover:
using the test command on files, strings and numbers; and
using the expr command on numbers and strings.
The expr tests and performs numeric output. Both test and expr will return 0 for true and 1 for false using the last exit status command $?.