Linux shell开发小细节分享

来源:互联网 发布:淘宝上买手机是正品吗 编辑:程序博客网 时间:2024/06/05 04:45

Linux shell编程:

   1.算数运算 ,使用 expr 外部程式或let 命令

#!/bin/sha=$1b=$2#判读参数为空处理if [ ! -n "$1" ]then   echo "First parametor is null"else   echo "First parametor is $1"filet c=$a+$bd=`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

 

0 0
原创粉丝点击