let 命令

let命令取代并扩展了expr命令的整数算数符号。

let除了支持5中基础的运算符。

还支持+=,-=,*=,、-,%= 自变运算符。

以及**幂次运算符。

在变量计算中不需要加上$来表示变量。

[centos@s201 ~]$ let a=1+2
[centos@s201 ~]$ echo $a
3
[centos@s201 ~]$ let b=3-2
[centos@s201 ~]$ echo $B

[centos@s201 ~]$ echo $b
1

[centos@s201 ~]$ let c=8/6
[centos@s201 ~]$ echo $c
1

[centos@s201 ~]$ let c=8%6
[centos@s201 ~]$ echo $c
2

 

自加操作:let no++
自减操作:let no--
简写形式 let no+=10,let no-=20,分别等同于 let no=no+10,let no=no-20

 

 

对空格比较严格

[centos@s201 ~]$ let c= 8/6
-bash: let: c=: syntax error: operand expected (error token is "=")
[centos@s201 ~]$ let c = 8/6
-bash: let: =: syntax error: operand expected (error token is "=")

 

posted @ 2019-05-18 14:36  wqbin  阅读(335)  评论(0编辑  收藏  举报