【发布时间】:2014-06-25 21:57:50
【问题描述】:
我希望命令仅在字符串变量不等于与 foo 或任何以 bar 开头的单词时执行。
if [[ $string != "foo" || $string != bar* ]]; then
commands
fi
当 $string=foo 和我使用以下代码时,它可以正常工作并且不执行任何命令:
if [[ $string != "foo" ]]; then
commands
fi
但是当我用 || 添加第二部分时命令在不应该执行的时候执行。
【问题讨论】:
-
你需要 && 而不是 ||。想想吧。
标签: if-statement logical-operators