bash — boolean expression evaluation without condition

后端 未结 2 2112
无人共我
无人共我 2021-01-25 13:01

I tried to play around with bash, and even tried documentation and few threads though I cannot seem to get it right.

S=(true false)
if (( ${S[0]} || ${S[1]} ))
t         


        
2条回答
  •  独厮守ぢ
    2021-01-25 13:49

    Instead of S=(true false), you need to create your array like this:

    S=(1 0)
    

    Then this if block:

    if (( ${S[0]} || ${S[1]} ))
    then
        echo "true"
    else
        echo "false"
    fi
    

    will output:

    true

    Please note that true/false are treated as literal strings "true" and "false" in BASH.

提交回复
热议问题