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

多个表达式if语句在Bash中

发布时间:2020-12-16 01:31:34 所属栏目:安全 来源:网络整理
导读:我想重新创建这样的东西 if ( arg1 || arg2 || arg 3) {} 我确实到目前为止,但是我收到以下错误 line 11: [.: command not foundif [ $char == $';' -o $char == $'' -o $char == $''' ]then ... 我尝试了不同的方式,但似乎没有工作some of the ones I tr
我想重新创建这样的东西
if ( arg1 || arg2 || arg 3) {}

我确实到目前为止,但是我收到以下错误

line 11: [.: command not found

if [ $char == $';' -o $char == $'' -o $char == $''' ]
then ...

我尝试了不同的方式,但似乎没有工作some of the ones I tried

对于bash,您可以使用[[]]形式而不是[],这允许&&和||内部:
if [[ foo || bar || baz ]] ; then
  ...
fi

否则,您可以在外部使用通常的布尔逻辑运算符:

[ foo ] || [ bar ] || [ baz ]

…或使用特定于测试命令的操作(though modern versions of the POSIX specification describe this XSI extension as deprecated — see the APPLICATION USAGE section):

[ foo -o bar -o baz ]

…这是以下不同的书面形式,它们同样被弃用:

test foo -o bar -o baz

(编辑:李大同)

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

    推荐文章
      热点阅读