$((40-35))が5になるのはなぜですか?

$((40-35))が5になるのはなぜですか?

これの後にはどのような奇妙なシェル構文が隠されており、$((40-35))値をどのように計算しますか?

例:

$> echo $((40-35))
5

ベストアンサー1

bashマニュアルページから:

  ((expression))
          The expression is evaluated according  to  the  rules  described
          below  under ARITHMETIC EVALUATION.  If the value of the expres-
          sion is non-zero, the return status is 0; otherwise  the  return
          status is 1.  This is exactly equivalent to let "expression".

そしてさらに進む:

  Arithmetic Expansion
    Arithmetic expansion allows the evaluation of an arithmetic expression and
    the substitution of the result.  The format for arithmetic expansion is:

          $((expression))

二重括弧内に入力するすべての内容は、bash評価できる数学式になります。

おすすめ記事