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

bash – 如果elif fi在shell脚本中使用

发布时间:2020-12-15 20:01:01 所属栏目:安全 来源:网络整理
导读:参见英文答案 Simple logical operators in Bash3答案我不知道如何做一个如果在shell中多个测试,我有麻烦写这个脚本: echo "You have provided the following arguments $arg1 $arg2 $arg3"if [ "$arg1" = "$arg2" "$arg1" != "$arg3" ]then echo "Two of
参见英文答案 > Simple logical operators in Bash3答案我不知道如何做一个如果在shell中多个测试,我有麻烦写这个脚本:
echo "You have provided the following arguments $arg1 $arg2 $arg3"
if [ "$arg1" = "$arg2" && "$arg1" != "$arg3" ]
then 
    echo "Two of the provided args are equal."
    exit 3
elif [ $arg1 = $arg2 && $arg1 = $arg3 ]
then
  echo "All of the specified args are equal"
  exit 0
else
  echo "All of the specified args are different"
  exit 4 
fi

问题是我每次得到这个错误:./compare.sh:[:missing`]’command not found
谢谢!

sh解释&&作为shell运算符。将其更改为-a,这是[的连接运算符:
[ "$arg1" = "$arg2" -a "$arg1" != "$arg3" ]

此外,你应该总是引用变量,因为[当你离开参数时感到困惑。

(编辑:李大同)

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

    推荐文章
      热点阅读