Linux shell编程:
1.算数运算 ,使用 expr 外部程式或let 命令
#!/bin/sh a=$1 b=$2 #判读参数为空处理 if [ ! -n "$1" ] then echo "First parametor is null" else echo "First parametor is $1" fi let c=$a+$b d=`expr $a \* $b` echo "SUM=$c Mul=$d"
注:expr 沒有乘幂 ,Linux运算符之间的空格谨慎注意。expr运算中“ * ”和“括号”前加“\”(转义)。
执行结果:
[root@localhost studyshell]# ./paramifnull.sh 4 5
First parametor is 4
SUM=9 Mul=20