1.算术运算符
加:+
减:-
乘: *
除:/
取余:%
赋值:=
使用的时候,需要使用单引号和expr
a=800
b=900
c=`expr $a + $b`
echo "c的值为:$c"
2.关系运算符
"-eq" 检测2个数是否相等,相等返回true
"-ne" 检测2个数是否不相等,不相等返回true
还有-gt -lt等:

3.布尔运算符
非:!
或:-o
与:-a

4.逻辑运算符
逻辑与 &&
逻辑或 ||

5.字符串运算符
主要检测字符串是否存在,相等:

6.文件测试运算符
-e 是否存在,-d是否为目录,-s是否为空
-r是否可读,-w是否可写,-x是否可执行。

网友评论