码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-10-20 01:10:47      阅读:193      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!