0
点赞
收藏
分享

微信扫一扫

Shell Scripts相关

独兜曲 2022-08-23 阅读 57

获得变量长度


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

举报

相关推荐

0 条评论