小编use*_*083的帖子

用逻辑OR打击if语句

我希望仅在字符串变量不等于 foo 以bar开头的任何单词时才执行命令。

if [[ $string != "foo" || $string != bar* ]]; then
commands
fi
Run Code Online (Sandbox Code Playgroud)

当$ string = foo并且我使用以下代码时,它可以正常工作,并且不执行任何命令:

if [[ $string != "foo" ]]; then
commands
fi
Run Code Online (Sandbox Code Playgroud)

但是当我用||添加第二部分时 命令在不应该执行时执行。

if-statement logical-operators

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

if-statement ×1

logical-operators ×1