bash 算术运算
基本算术运算符
- 加, -减, *乘, /除, **取模
bash中的let支持的算术运算符
使用help let 查看bash的运行符和表达式
id++, id-- variable post-increment, post-decrement
++id, --id variable pre-increment, pre-decrement
-, + unary minus, plus
!, ~ logical and bitwise negation
** exponentiation
*, /, % multiplication, division, remainder
+, - addition, subtraction
<<, >> left and right bitwise shifts
<=, >=, <, > comparison
==, != equality, inequality
& bitwise AND
^ bitwise XOR
| bitwise OR
&& logical AND
|| logical OR
expr ? expr : expr
conditional operator
=, *=, /=, %=,
+=, -=, <<=, >>=,
&=, ^=, |= assignment
bash 算术运算
(1) let var = 算术表达式 注意运算项之间不能由空格
例如:let a=2+3
let b=$a+$b
(2) var = $[算术表达式]
例如: a=$[2+3]
b=$[$m+$n]
echo " this is the $[$x+$y] time"
(3) var=$(($x+$y))
例如: echo $((3+4))
(4) var=$(expr arg1 符号 arg3...)
例如: echo $(expr 1 + 3)
echo $(expr 2 * 10) 算法符号需要转义
bash随机数生成器
BASH内建的随机数生成器 $RANDOM可以生成1-32767之间的随机数