本文介绍了在Bash中具有多个表达式的复合if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新创建这样的东西

I would like to recreate something like this

if ( arg1 || arg2 || arg 3) {}

到目前为止,我确实做到了,但是出现了以下错误

and I did got so far, but I get the following error

line 11: [.: command not found

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

我尝试了不同的方法,但似乎没有任何效果.我尝试过的一些

I tried different ways but none seem to work some of the ones I tried

推荐答案

对于Bash,您可以使用[[ ]]形式而不是[ ]形式,该形式允许内部使用&&||:

For Bash, you can use the [[ ]] form rather than [ ], which allows && and || internally:

if [[ foo || bar || baz ]] ; then
  ...
fi

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

Otherwise, you can use the usual Boolean logic operators externally:

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

...或使用特定于test命令的运算符(尽管是现代版本POSIX规范中的XSI扩展已弃用-请参见应用程序使用情况"部分):

...or use operators specific to the test command (though modern versions of the POSIX specification describe this XSI extension as deprecated -- see the APPLICATION USAGE section):

[ foo -o bar -o baz ]

...这是以下内容的不同书写形式,已被弃用:

...which is a differently written form of the following, which is similarly deprecated:

test foo -o bar -o baz

这篇关于在Bash中具有多个表达式的复合if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 01:02