下列是運算子列表,以相同優先序為群組,越往下優先權越低 (優先序 和 C 語言一樣?)。括號裡的算式會先算。
| id++ id-- | post-increment and post-decrement |
| ++id --id | pre-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:expr | conditional operator |
| = *= /= %= += -= <<= >>= &= ^= |= | assignment |
| expr1 , expr2 | comma |
參考:
- osl3 Shell 設計入門: 10.算術運算 (另外還有 expr、$[]、let 三種,其中 expr 可攜性較好)
- Shell Script 文章
- bash man-page ARITHMETIC EVALUATION
沒有留言:
張貼留言