bash – shell脚本:if语句

在这里按照教程: http://bash.cyberciti.biz/guide/If..else..fi#Number_Testing_Script

我的脚本看起来像:

lines=`wc -l $var/customize/script.PHP`
if test $lines -le 10
then
    echo "script has less than 10 lines"
else
    echo "script has more than 10 lines"
fi

但我的输出看起来像:

./boot.sh: line 33: test: too many arguments
script has more than 10 lines

为什么说我有太多的论点?我没有看到我的脚本与教程中的脚本有何不同.

wc -l file命令会打印两个单词.试试这个:
lines=`wc -l file | awk '{print $1}'`

要调试bash脚本(boot.sh),您可以:

$bash -x ./boot.sh

它将打印每一行执行.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...