在shell中,let命令用于指定算术运算,即 let expretion。
实例如下:
#!/usr/bin/env bash
a=2
echo “a init is $a”
let “a+=1”
echo “a+=1 is $a”
let “a-=1”
echo “a-=1 is $a”
let “a*=2”
echo “a*=2 is $a”
let “a/=2”
echo “a/=2 is $a”
let “a=$a**3”
echo “a=a**3 is $a”
运行结果:
a init is 2
a+=1 is 3
a-=1 is 2
a*=2 is 4
a/=2 is 2
a=a**3 is 8
版权声明:本文为chinabestchina原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。