关于bash的多个条件'如果'声明

时间:2018-03-18 18:20:40

标签: bash if-statement

我在bash中遇到麻烦。 基本上我试图在bash中这样做:

if ((x='r')&&(y='s'))||((x='s')&&(y='p')) then
echo "bluh"

但是我找不到合适的方法,使用方括号,2个方括号,圆括号。

但它只是赢了工作......

1 个答案:

答案 0 :(得分:2)

(( ))适用于 bash算术,而您需要[[ ]] bash test:

if [[ ( $x == r && $y == s ) || ( $x == s && $y == p ) ]]; then
    echo "bluh"
fi

[[是一个类似于[命令(但功能更强大)的bash关键字。请参阅http://mywiki.wooledge.org/BashFAQ/031http://mywiki.wooledge.org/BashGuide/TestsAndConditionals。除非您是为POSIX sh编写的,否则我们建议使用[[

相关问题