多个表达式if语句在Bash中

前端之家收集整理的这篇文章主要介绍了多个表达式if语句在Bash中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想重新创建这样的东西
  1. if ( arg1 || arg2 || arg 3) {}

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

  1. line 11: [.: command not found
  2.  
  3. if [ $char == $';' -o $char == $'\\' -o $char == $'\'' ]
  4. then ...

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

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

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

  1. [ foo ] || [ bar ] || [ baz ]

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

  1. [ foo -o bar -o baz ]

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

  1. test foo -o bar -o baz

猜你在找的Bash相关文章