Shell Programming/expr command

expr 1 | expr 2
Expression 1 if expression 1 is non-zero, otherwise expression 2.

expr 1 | expr 2 1       0 -> Expression 1 1       1 -> Expression 1 0       0 -> Expression 2 0       1 -> Expression 2

expr 1 & expr 2
Zero if either expression is zero, otherwise expression 1.

expr 1 & expr 2 0       0 -> 0   1        0 -> 0   0        1 -> 0   1        1 -> Expression 1

Other operations in expr command
The expr command is useful in simple arithmetic operations using integers only.

expr 1 + 1

output: 2

Similarly,

expr 1 - 1 expr 1 * 1 expr 1 / 1 expr 1 % 1

which have following results, respectively: 0; 1; 1; 0. Note that % is modulus.