Comparison of Expressions

The way the logical comparison of two operators (numeric or string) is done varies slightly in different shells. In pdksh and bash, a command called test can be used to achieve comparisons of expressions. In tcsh, you can write an expression to accomplish the same thing.

pdksh and bash

This section covers comparisons using the pdksh or bash shells. Later in the chapter, the section tcsh contains a similar discussion for the tcsh shell.

The syntax of the test command is as follows:

test expression

or

[ expression ]

Both forms of test commands are processed the same way by pdksh and bash. The test commands support the following types of comparisons:

  • String comparison

  • Numeric comparison

  • File operators

  • Logical operators ...

Get Red Hat® Linux® 7 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.