• [SHELL]:let 命令详解


    [SHELL]:let 命令详解

     let :简单的计算器 
     
    语 法
    let[计算表达式]功 能let 命令:是 BASH中用于计算的工具,提供常用运算符还提供了方幂“**”运算符。在变量的房屋计算中不需要加上$来表示变量,如果表达式的值是非0,那么返回的状态值是0;否则,返回的状态值是1
    类似命令: wc  bc  dc  expr     
     
    执行权限: 超级用户 普通用户 
     
    命令属性: 系统管理
     

    参数必要参数


    选择参数

    范例


    范例1:BASH脚本中,简单算
    [rootlx138.com ~]# cat test1.sh //加法运算
    #!/bin/bash
    let a=5+4 b=9-3
    echo $a $b
    [rootlx138.com ~]# ./test1.sh
    9 5

    [rootlx138.com ~]# cat test2.sh 
    #!/bin/bash
    b=5
    let "t1 = ((a = 5 + 3, b = 7 - 1, c = 15 - 4))"
    echo "t1 = $t1, a = $a, b = $b"

    范例2: let的一些理解

    [rootlx138.com ~]# cat test3.sh 
    #!/bin/bash
    $t=122
    let t=$t+1
    echo $t
    [rootlx138.com ~]# ./test3.sh 
    123
    [rootlx138.com ~]#cat test4.sh 
    #!/bin/bash
    t=122
    t=$t+1
    echo $t
    [rootlx138.com ~]# ./test4.sh 
    122+1
    在SHELL中,变量是没有类型的,如果变量的值都是数字,那么其可以视为整数,如果有字母,那么就当做字符串。

     t=122

    let t+=1  #123

    t=11B

    let t+=1 #1

     Linux命令在线查询(http://www.lx138.com),let  命令 详解:http://www.lx138.com/page.php?ID=439

     1 在shell中,let命令用于指定算术运算,即 let expretion。
     2 
     3 实例如下:
     4 
     5 #!/usr/bin/env bash
     6 a=2
     7 echo "a init is $a"
     8 let "a+=1"
     9 echo "a+=1 is $a"
    10 let "a-=1"
    11 echo "a-=1 is $a"
    12 let "a*=2"
    13 echo "a*=2 is $a"
    14 let "a/=2"
    15 echo "a/=2 is $a"
    16 let "a=$a**3"
    17 echo "a=a**3 is $a"
    18 
    19 
    20 
    21 运行结果:
    22 
    23 a init is 2
    24 a+=1 is 3
    25 a-=1 is 2
    26 a*=2 is 4
    27 a/=2 is 2
    28 a=a**3 is 8
    29 --------------------- 
    30 作者:panda-star 
    31 来源:CSDN 
    32 原文:https://blog.csdn.net/chinabestchina/article/details/72857617 
    33 版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    4.1.7 POD对象
    异常处理
    POJ3167 Cow Patterns [KMP]
    POJ1961 Period [KMP应用]
    POJ2778 DNA Sequence [AC自动机+矩阵]
    HDU2243 考研路茫茫——单词情结 [AC自动机+矩阵]
    POJ2185 Milking Grid [KMP应用]
    POJ2541 Binary Witch [状态压缩]
    ZOJ3430 Detect the Virus [AC自动机]
    POJ2752 Seek the Name, Seek the Fame [KMP]
  • 原文地址:https://www.cnblogs.com/LiuYanYGZ/p/9838096.html
Copyright © 2020-2023  润新知