在shell脚本中,使用-eq、-ne、-gt、-ge、-lt、-le进行整数的比较。英文意思分别为:
-eq :equal(相等)
-ne :not equal(不等)
-gt :greater than(大于)
-ge :greater than or equal(大于或等于)
-lt :less than(小于)
-le :less than or equal(小于或等于)
注意:在shell中这些符号只能用于整数的比较,不能用于字符串。
一个小经验:
①在执行如下代码的时候,记得echo之后的变量一定要用“”(双引号)括起来,不括的话一般情况下没有问题,但是在遇到如line的值为“** RTV Order **”这种情况时,我的代码出错了。$1是一个文件变量。-z :判断字符串是否为null,即长度为0(zero)。 -n :判断字符串不为空(non-zero).
so_ship_line=""
exec 3<$1
while read -u3 line
do
if [ -z "$so_ship_line" ];then
read so_ship_line <<< ` echo "$line" | sed -n '/\*\* S\/O Shipped /p' `
# echo "so_ship_line:$so_ship_line"
else
read dollar_ship_line <<< ` echo "$line" | sed -n '/Kdollar Ship/p' `
if [ -n "$dollar_ship_line" ];then
echo "$dollar_ship_line" >> Fiscal_temp.log
dollar_ship_array=($dollar_ship_line)
# echo "dollar_ship_line:$dollar_ship_line"
# echo ${#dollar_ship_array[@]} "============" ${dollar_ship_array[@]}
break
fi
fi
done