Arithmetic Expressionsby Pigbrain

Arithmetic Expressions

  • Bash는 다음 2가지 방법으로 산술 연산을 제한하고 있다
    • $((expr))
    • let expressions


OperatorDescription
++ -- Auto-increment and auto-decrement, both prefix and postfix
+ - Unary plus and minus
! ~ Logical negation and binary inversion (one’s complement)
** Exponentiation
* / % Multiplication, division, modulus
<< >> Bitwise left shift, bitwise right shift
== != Equality, inequality
& Bitwise AND
^ Bitwise exclusive OR
Bitwise OR
&& Logical AND (short circuit)
││ Logical OR (short circuit)
?: Inline conditional evaluation
, Sequential expression evaluation


Example

prompt> let "i = 10 + 2"
prompt> echo $i
12

prompt> echo $((2 ** 4))
16  


참고

Published 20 March 2016