Comparison of Expressions in pdksh and bash

Comparing values or evaluating the differences between similar bits of datasuch as file information, character strings, or numbersis a task known as comparison of expressions. Comparison of expressions is an integral part of using logic in shell programs to accomplish tasks. 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.

The following section covers comparison operations using the pdksh or bash shells. Later in the chapter, you learn how to compare expressions in the tcsh shell.

The pdksh and bash shell syntax provide a command named test to compare strings, numbers, and files. The syntax of the test command is as follows:

test expression or

[ expression ]

Both forms of the 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

Was this article helpful?

0 0

Post a comment