直接上脚本,
使用$(())以及$[]进行数字计算
数值比较:
n1 -eq n2检查n1是否等于n2 n1 -le n2检查n1是否小于等于n2
n1 -ge n2检查n1是否大于等于n2 n1 -lt n2检查n1是否小于n2
n1 -gt n2检查n1是否大于n2 n1 -ne n2检查n1是否不等于n2
#!/bin/bash
numa=;
numb=;
numc1=$(($numa - $numb));
numc2=$[$numa + $numb];
echo "numc1 = $numc1, numc2 = $numc2" if [ $numc1 -lt ]
then
echo "numc1 less then 0"
fi if [ $numc2 -gt ]
then
echo "numc2 great then 0"
fi numd1=$(($numc1 + ));
numd2=$[$numc2 - ]; echo "numd1 = $numd1, numd2 = $numd2" if [ $numd1 -gt $numd2 ]
then
echo "numd1 great then numd2"
else
echo "numd1 not great then numd2"
fi
参考:
http://www.cnblogs.com/linuxer/archive/2012/06/20/2870518.html