shell简单用法笔记(shell中数值运算)二时间:2023-03-09 02:18:55 shell中变量值,如果不手动指定类型,默认都是字符串类型: 例如: a= b= c=$a+#b echo $c 结果会输出:123+456 shell中,如果要进行数值运算,可以通过一下方法: 方法1: a= b= c=$(($a+$b)) 方法2: a= b= declare -i c=$a+$b 通过declare -i 来声明c的数值类型为int类型 方法3: a= b= c=$(expr $a + $b) 注意+号两边有空格 通过貂绒expr命令来进行字符串的加减