加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – shell脚本:if语句

发布时间:2020-12-16 01:27:22 所属栏目:安全 来源:网络整理
导读:我在这里按照教程: http://bash.cyberciti.biz/guide/If..else..fi#Number_Testing_Script 我的脚本看起来像: lines=`wc -l $var/customize/script.php`if test $lines -le 10then echo "script has less than 10 lines"else echo "script has more than 1
我在这里按照教程: 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

它将打印每一行执行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读