[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 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!