shell脚本中的小数运算:
awk:
- hadoop@Mcnode1:~/cloud/adam/xubo/data/test20160310/test$catdemical.sh
- #!/bin/bash
- echo`awk-vx=2.45-vy=3.123'BEGIN{printf"%.2f\n",x*y}'`
- s=1.5
- echo$s
- echo`awk-vx=2.45-vy="$s"'BEGIN{printf"%.2f\n",x*y}'`
- hadoop@Mcnode1:~/cloud/adam/xubo/data/test20160310/test$catdemical.sh
- #!/bin/bash
- s=1.5
- echo$s
- #product=`awk-vx=2.45-vy="$s"'BEGIN{printf"%.2f\n",0);background-color:inherit;">
- s2=$(echo"scale=3;6/5"|bc)
- echo$s2
- s3=$(echo"scale=3;$s/5"|bc)
- echo$s3
把字符串转成数组:
- #!/bin/bash
- str="1,2,3,4";
- //与/之间与分割的字符,另外/后有一个空格不可省略
- str=${str//,/};
- arr=($str);
- #遍历数组
- foreachin${arr[*]}
- do
- echo$each
- done
Linux let:
#!/bin/bash let a=5+4 b9-3 echo $a $b@H_404_143@
死循环:
while true
do
......
done