zoukankan      html  css  js  c++  java
  • Linux中的数值运算

    方法1:
      declare -i 变量=$变量1+$变量2
        a.变量和=之间不能有空格
        b.变量和+之间不能有空格
    [root@localhost ~]# a=1
    [root@localhost ~]# b=2
    [root@localhost ~]# declare -i c=$a+$b
    [root@localhost ~]# echo $c
    3

    方法2:
      变量=$(expr $变量 + $变量)
        a.=左右两边不能有空格
        b.+左右两边必须有空格
    [root@localhost ~]# a=1
    [root@localhost ~]# b=2
    [root@localhost ~]# c=$(expr $a + $b)
    [root@localhost ~]# echo $c
    3

    方法3:
      变量=$((运算式))
        a.=左右两边不能有空格
        b.运算式随便写,很自由
    [root@localhost ~]# a=1
    [root@localhost ~]# b=2
    [root@localhost ~]# c=$(($a + $b))
    [root@localhost ~]# echo $c
    3

    方法3:
      变量=$[运算式]
        a.=左右两边不能有空格
        b.运算式随便写,很自由
    [root@localhost ~]# a=1
    [root@localhost ~]# b=2
    [root@localhost ~]# c=$[$a + $b + 1]
    [root@localhost ~]# echo $c
    4

  • 相关阅读:
    Linux用户、用户组、文件权限设置
    spring,springMvc和mybatis整合配置
    spring,springMvc和hibernate整合
    spring与mybatis
    spring与Dbcp
    初识事物
    spring与Aop
    初识spring
    mysql 完整性约束
    mysql数据库的基本操作
  • 原文地址:https://www.cnblogs.com/413xiaol/p/7158216.html
Copyright © 2011-2022 走看看