Wednesday, October 31, 2007

Evaluate Constants and Strings with expr Command

The expr command is a handy utility for evaluating constants and strings via the command line interface. Here are a few examples of expressions.

# expr 9 \* 9
81
# expr 9 / 9
1
# expr 9 + 9
18
# expr 9 - 9
0
# expr 9 % 9
0
# expr 50 - 100
-50
# expr 6 + 8 \* 9
78
# expr 9 \* \( 2 + 6 \)
72

Evaluate relational operators: true (1) or false (0)

# expr aaa \< myblog
1
# expr aaa \> myblog
0
# expr aaa == myblog
0
# expr aaa != myblog
1
# expr 8 \<> 9
0
# expr 8 != 9
1
# expr 8 \<= 9
1

No comments: