如何在bash中完成以下内容?
if ("$a" == "something" || ($n == 2 && "$b" == "something_else")); then
...
fi
答案 0 :(得分:22)
你几乎得到了它:
if [[ "$a" == "something" || ($n == 2 && "$b" == "something_else") ]]; then
实际上,由于运算符优先级,括号可以省略,所以它也可以写成
if [[ "$a" == "something" || $n == 2 && "$b" == "something_else" ]]; then
答案 1 :(得分:2)
if [[ "$a" == "something" ]] || [[ $n == 2 && "$b" == "something_else" ]]; then
...
fi