linux命令:浅谈shell中如何进行算术运算
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux命令:浅谈shell中如何进行算术运算相关的知识,希望对你有一定的参考价值。
1、let 算术运算表达式
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、$[算术运算表达式]
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、$((算术运算表达式))
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 算术运算表达式,表达式中各操作数及运算符之间要有空格,而且要使用命令引用
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
本文出自 “学linux历程” 博客,请务必保留此出处http://woyaoxuelinux.blog.51cto.com/5663865/1863517
以上是关于linux命令:浅谈shell中如何进行算术运算的主要内容,如果未能解决你的问题,请参考以下文章