一个小脚本问题

作者: yyyunwei 2016-01-12 11:22:46
有个练习
写一个脚本
  判定命令历史中历史命令的总条目是否大于1000;
  如果大于,则显示"Some command will gone.";否则显示"OK".

运行结果如图1:
[attach]42389[/attach]
求解.
code:
#!/bin/bash
historysum=`history | wc -l`
#historysum=4444
echo "the history sum is :$historysum."
if [ $historysum -gt 1000 ];then
echo "some command will gone."
else
echo "ok."
fi


修改之后图2:也无法运行正确的结果
[attach]42390[/attach]
[attach]42391[/attach]

code:
#!/bin/bash
historysum=`history | tail -1 | cut -d' ' -f2`
#historysum=4444
echo "the history sum is :$historysum."
if [[ $historysum -gt 1000 ]];then
echo "some command will gone."
else
echo "ok."
fi

相关资讯