1 , let arithmetic op-expression
Let c= $A + $B
Eg:a=3 b=5 let c= $A + $B
Echo $C
[Email protected] test]# a=3
[Email protected] test]# b=3
[[email protected] test]# let c= $A + $B
[Email protected] test]# echo $C
6
2 , $[arithmetic operation expression]
c=$[$A + $B]
eg:a=2 b=6 c=$[$A + $B]
Echo $C
[Email protected] test]# a=2
[Email protected] test]# b=6
[Email protected] test]# c=$[$A + $B]
[Email protected] test]# echo $C
8
3 , $ ((arithmetic expression))
c=$ (($A + $B))
Eg:a=6 b=7 c=$ (($A + $B))
Echo $C
[Email protected] test]# a=6
[Email protected] test]# b=7
[[email protected] test]# c=$ (($A + $B))
[Email protected] test]# echo $C
13
4 , expr arithmetic expression, a space between operands and operators in an expression, and a command reference
c= ' expr $A + $B '
eg:a=5 b=6 c= ' expr $A + $B '
Echo $C
[Email protected] test]# a=5
[Email protected] test]# b=6
[[email protected] test]# c= ' expr $A + $B '
[Email protected] test]# echo $C
11
This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1863517
Linux commands: Talking about how to perform arithmetic operations in the shell