shell--shell中的数学计算

shell--shell中的数学计算

shell中如何计算

默认情况下shell不能直接进行算术运算,必须使用数学计算命令
这是因为在Bash shell中每一个变量的值都是字符串,无论你有没有用引号,都会用引号进行存储。
shell--shell中的数学计算

(( ))整数计算

shell--shell中的数学计算shell--shell中的数学计算
shell--shell中的数学计算

简单的数值计算

shell--shell中的数学计算shell--shell中的数学计算

复杂的综合算术运算

shell--shell中的数学计算
shell--shell中的数学计算

逻辑运算

1真0假

shell--shell中的数学计算

自增/自减计算

shell--shell中的数学计算shell--shell中的数学计算

多个表达式同时计算

shell--shell中的数学计算

let命令的整数数学运算

let和(( ))的用法类似
shell--shell中的数学计算
shell--shell中的数学计算

let和(( ))的区别

shell--shell中的数学计算

实际运算

shell--shell中的数学计算

expr计算

shell--shell中的数学计算

注意
shell--shell中的数学计算shell--shell中的数学计算shell--shell中的数学计算

bc命令(小数计算)

bc是linux下的计算器,除了作为计算器使用,还可以作为命令行计算工具来使用。
如果计算器中没有安装bc,可以使用

yum whatprovides */bc来查看文件,并且安装
shell--shell中的数学计算

管道符使用

shell--shell中的数学计算

配合变量使用

shell--shell中的数学计算

[ ]运算

shell--shell中的数学计算