1 #!/bin/bash 2 #算术运算符实例 3 a=10 4 b=20 5 6 val=`expr $a + $b` 7 echo "a + b : $val" #30 8 9 val=`expr $a - $b` 10 echo "a - b : $val" #-10 11 12 val=`expr $a \* $b` #不加转义符号(\)会报错:expr: syntax error 13 echo "a * b : $val" #200 14 15 val=`expr $a / $b` 16 echo "b / a : $val" #0 17 18 val=`expr $a % $b` 19 echo "b % a : $val" #10 20 21 22 if [ $a == $b ] 23 then 24 echo "a等于b" 25 fi 26 27 if [ $a != $b ] #b与]之间不加空格时会报错:./test.sh: line 27: [: missing `]' 28 then 29 echo "a不等于b" 30 fi