首页 > Linux操作系统 > Linux操作系统 > Shell Scripts相关
获得变量长度
length = ${#var}
识别root用户
#!/bin/bash
if [ $UID -ne 0 ]; then
echo "I'm not root"
else
echo "I'm root!"
fi
数学运算
#!/bin/bash
n1=4;
n2=5;
let result=n1+n2
echo $result
let不支持小数
bc用于数学计算的高级工具。
echo "sqrt(1.44)" | bc
echo "10^2" | bc
chenyj@hotcomp:~/shellscripts$ echo "sqrt(1.44)" | bc
1.20
chenyj@hotcomp:~/shellscripts$ echo "10^2" | bc
100
chenyj@hotcomp:~/shellscripts$ echo "10^4" | bc
10000
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8520577/viewspace-2907566/ ,如需转载,请注明出处,否则将追究法律责任。