加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell小结

发布时间:2020-12-15 19:48:40 所属栏目:安全 来源:网络整理
导读:shell脚本中的小数运算: awk: hadoop@Mcnode1:~/cloud/adam/xubo/data/test20160310/test$catdemical.sh #!/bin/bash echo`awk-vx=2.45-vy=3.123'BEGIN{printf"%.2fn",x*y}'` s=1.5 echo$s echo`awk-vx=2.45-vy="$s"'BEGIN{printf"%.2fn",x*y}'` bc: had

shell脚本中的小数运算:

awk:

  1. hadoop@Mcnode1:~/cloud/adam/xubo/data/test20160310/test$catdemical.sh
  2. #!/bin/bash
  3. echo`awk-vx=2.45-vy=3.123'BEGIN{printf"%.2fn",x*y}'`
  4. s=1.5
  5. echo$s
  6. echo`awk-vx=2.45-vy="$s"'BEGIN{printf"%.2fn",x*y}'`
bc:
  1. hadoop@Mcnode1:~/cloud/adam/xubo/data/test20160310/test$catdemical.sh
  2. #!/bin/bash
  3. s=1.5
  4. echo$s
  5. #product=`awk-vx=2.45-vy="$s"'BEGIN{printf"%.2fn",0);background-color:inherit;">
  6. s2=$(echo"scale=3;6/5"|bc)
  7. echo$s2
  8. s3=$(echo"scale=3;$s/5"|bc)
  9. echo$s3

把字符串转成数组:

    #!/bin/bash
  1. str="1,2,3,4";
  2. //与/之间与分割的字符,另外/后有一个空格不可省略
  3. str=${str//,/};
  4. arr=($str);
  5. #遍历数组
  6. foreachin${arr[*]}
  7. do
  8. echo$each
  9. done

Linux let:

#!/bin/bash

let a=5+4
 b9-3 
echo $a $b

死循环:

while true

do

......

done

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读