小蚂蚁 发表于 2022-7-26 11:49:05

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

http://blog.itpub.net/8520577/viewspace-2907566/
页: [1]
查看完整版本: Shell Scripts相关