zoukankan      html  css  js  c++  java
  • shell 基础4

    数值运算:

    declare:声明变量类型

    declare [+/-][选项] 变量名
    选项:
    -:给变量设定类型属性
    +:取消变量的类型属性
    -i:将变量声明为整数型(integer)
    -x:将变量声明为环境变量
    -p:显示指定变量的被声明的类型

    [root@localhost tmp]# aa=11
    [root@localhost tmp]# bb=22
    [root@localhost tmp]# cc=$aa+$bb
    [root@localhost tmp]# echo $cc
    11+22

    方法一:
    [root@localhost tmp]# declare -i cc=$aa+$bb
    [root@localhost tmp]# echo $cc
    33

    方法二:
    [root@localhost tmp]# aa=11
    [root@localhost tmp]# bb=22
    [root@localhost tmp]# dd=$(expr $aa + $bb)
    [root@localhost tmp]# echo $dd
    33
    说明:+号两侧的空格不能省略

    方法三:
    [root@localhost tmp]# aa=11
    [root@localhost tmp]# bb=22
    [root@localhost tmp]# ee=$(($aa + $bb))
    [root@localhost tmp]# echo $ee
    33


    [root@localhost tmp]#
    [root@localhost tmp]# declare -p cc
    declare -i cc="33"
    [root@localhost tmp]# declare -p aa
    declare -- aa="11"
    [root@localhost tmp]# declare -p bb
    declare -- bb="22"

  • 相关阅读:
    php 函数汇总
    php 图片base64编码生成dataurl和保存为图片
    bootstrap
    PHPWord
    js json排序
    UE用法
    判断移动端是苹果还是安卓,以及安卓版本
    shell终极操作
    LINUX yum用法
    jquery对checkbox的操作汇总
  • 原文地址:https://www.cnblogs.com/javasl/p/11155131.html
Copyright © 2011-2022 走看看