标签:sed lse exp 代码 span style str test shell
【原代码】
Mem_Usage=91.00
CPU_Usage=85.00
if [[ `expr $Mem_Usage \> 90.00` -eq 1 ]];then
echo "Memory highly used! "
elif [[ `expr $CPU_Usage \> 80.00` -eq 1 ]];then
echo "CPU highly used! "
elif [[ `expr $Mem_Usage \> 90.00` -eq 1 ]] && [[ `expr $CPU_Usage \> 80.00` -eq 1 ]];then
echo "Memory && CPU highly used!"
else
echo "Memory && CPU used normal!"
fi
调试运行结果:错误
# sh -x test.sh
+ Mem_Usage=91.00
+ CPU_Usage=95.00
++ expr 91.00 ‘>‘ 90.00
+ [[ 1 -eq 1 ]]
+ echo ‘Memory highly used! ‘
Memory highly used!
------------------------------------------------------------------我是可爱的分割线-------------------------------------------------------------
【修改后的代码】
Mem_Usage=91.00
CPU_Usage=85.00
if [ `expr $Mem_Usage \> 90.00` -eq 1 ] && [[ `expr $CPU_Usage \> 80.00` -eq 1 ];then
echo "Memory && CPU highly used!"
elif [ `expr $CPU_Usage \> 80.00` -eq 1 ];then
echo "CPU highly used! "
elif [ `expr $Mem_Usage \> 90.00` -eq 1 ];then
echo "Memory highly used! "
else
echo "Memory && CPU used normal!"
fi
调试结果输出:正确
# sh -x test.sh
+ Mem_Usage=91.00
+ CPU_Usage=95.00
++ expr 91.00 ‘>‘ 90.00
+ [[ 1 -eq 1 ]]
++ expr 95.00 ‘>‘ 80.00
+ [[ 1 -eq 1 ]]
+ echo ‘Memory && CPU highly used!‘
Memory && CPU highly used!
[Shell编程]写了一段shell代码,运行发现代码块(标红的)执行的预期结果出不来,谁能帮我看看?
标签:sed lse exp 代码 span style str test shell
原文地址:https://www.cnblogs.com/cnskylee/p/12971495.html