2013年11月25日 星期一

bash ARITHMETIC EVALUATION

bash 的算術運算用在內建指令 letdeclare、複合指令 (( ))、和算術擴展,使用固定寬度的整數,不檢查溢位,除以 0 會補抓為錯誤。

下列是運算子列表,以相同優先序為群組,越往下優先權越低 (優先序 和 C 語言一樣?)。括號裡的算式會先算。
id++ id--post-increment and post-decrement
++id --idpre-increment and pre-decrement
- +unary minus and plus
! ~logical and bitwise negation
**exponentiation
* / %multiplication, division, remainder
+ -addition, subtraction
<< >>left and right bitwise shifts
<= >= < >comparison
== !=equality and inequality
&bitwise AND
^bitwise exclusive OR
|bitwise OR
&&logical AND
||logical OR
expr?expr:exprconditional operator
= *= /= %= += -= <<= >>= &= ^= |=assignment
expr1 , expr2comma

參考:
  1. osl3 Shell 設計入門: 10.算術運算 (另外還有 expr、$[]、let 三種,其中 expr 可攜性較好)
  2. Shell Script 文章
  3. bash man-page ARITHMETIC EVALUATION 

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...