首页 > 系统服务 > 详细

linux命令:浅谈shell中如何进行算术运算

时间:2016-10-20 01:08:06      阅读:181      评论:0      收藏:0      [点我收藏+]

1、let 算术运算表达式

       let C=$A+$B

eg: A=3  B=5  let C=$A+$B

   echo $C 

[root@xuelinux test]# A=3

[root@xuelinux test]# B=3

[root@xuelinux test]# let C=$A+$B

[root@xuelinux test]# echo $C

6


2、$[算术运算表达式]

       C=$[$A+$B]

eg: A=2  B=6  C=$[$A+$B]

    echo $C

[root@xuelinux test]# A=2

[root@xuelinux test]# B=6

[root@xuelinux test]# C=$[$A+$B]

[root@xuelinux test]# echo $C

8


3、$((算术运算表达式))

       C=$(($A+$B))

eg: A=6   B=7   C=$(($A+$B))

    echo $C

[root@xuelinux test]# A=6

[root@xuelinux test]# B=7

[root@xuelinux test]# C=$(($A+$B))

[root@xuelinux test]# echo $C

13


4、expr 算术运算表达式,表达式中各操作数及运算符之间要有空格,而且要使用命令引用

       C=`expr $A + $B`

 eg: A=5   B=6   C=`expr $A + $B`

     echo $C

[root@xuelinux test]# A=5

[root@xuelinux test]# B=6

[root@xuelinux test]# C=`expr $A + $B`

[root@xuelinux test]# echo $C

11



本文出自 “学linux历程” 博客,请务必保留此出处http://woyaoxuelinux.blog.51cto.com/5663865/1863517

linux命令:浅谈shell中如何进行算术运算

原文:http://woyaoxuelinux.blog.51cto.com/5663865/1863517

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!