庆典 - 布尔前$ P $无条件pssion评价 [英] bash — boolean expression evaluation without condition

查看:101
本文介绍了庆典 - 布尔前$ P $无条件pssion评价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图玩弄庆典,甚至试图文件和<一个href=\"http://stackoverflow.com/questions/9906041/bash-boolean-ex$p$pssion-and-its-value-assignement\">few线程虽然我似乎无法得到它的权利。

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]} ))
then
    echo "true"
else
    echo "false"
fi


  • 如何布尔前pression可以在bash评估? (任何机会,以解决上面的代码片段?)

  • 是否有可能,如果来评价它,而不,即直接分配给一个变​​量(如无操作)?

    • how can the boolean expression be evaluated under bash? (any chance to fix the snippet above?)
    • is there any possibility to evaluate it without if, i.e. assign it to a variable directly (no if manipulation)?
    • 推荐答案

      (真假),你需要创建您的数组是这样的:

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

      S=(1 0)
      

      那么这个if块:

      Then this if block:

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

      将输出:

      真正

      请注意,真/假被视为文字字符串真与假在bash。

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

      这篇关于庆典 - 布尔前$ P $无条件pssion评价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆