First page Back Continue Last page Summary Graphic

Expr and Test

  • expr Can be used to perform simple math expressions (plus other stuff)
  • test Can be used to evaluate logical expressions (plus other stuff)
  • Abbreviate with []'s
  • Numeric logical operators include String operators include
  • -le, -ge, -lt, -gt, -eq, -ne =, !=
  • e.g.
  • a=1
  • gonzo_1="hello"
  • gonzo_2="there"
  • while [ $a -le 10 ]; do
  • /bin/echo "[$a]\c"
  • eval gonzo_value=\$gonzo_$a
  • if [ $a -eq 3 ]; then
  • eval gonzo_$a=1
  • fi
  • if [ "$gonzo_value" != "" ]; then
  • /bin/echo "$gonzo_value \c"
  • fi
  • a=`expr $a + 1`
  • done
  • --> [1]hello [2]there [3]1 [4][5][6][7][8][9][10]

    Notes: