shell补-运算-数字运算
RANDOM
[root@localhost sub_str]# man bash ###/RANDOM
.........
RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be
initialized by assigning a value to RANDOM. If RANDOM is
unset, it loses its special properties, even if it is subsequently reset.
[root@localhost sub_str]# echo $RANDOM
5747
[root@localhost sub_str]# echo $RANDOM
778
bc的进制转换
##11转换为16进制。 16进制10就是A了注意
[root@localhost ~]# echo "obase=16;11"|bc
B
[root@localhost ~]#
awk 'BEGIN{}' 在脚本进行统计计算
[root@localhost ~]# awk 'BEGIN{print 1+2}'
3
[root@localhost ~]# var1=1;var2=2
[root@localhost ~]# echo `expr $var1 + $var2 `
3
[root@localhost ~]# awk -vv=var1 -vy=var2 'BEGIN{print v+y}'
0
[root@localhost ~]# awk -v v=$var1 -v y=$var2 'BEGIN{print v+y}' ###-v给变量传入值可以不要空格写成-vv=$var1 -vy=$var2
3
[root@localhost ~]#
###########################
[root@localhost sub_str]# cat calculationtestawk.sh
#!/bin/bash
#
#
a=${1}
b=${2} ####多用变量,程序代码就不用经常调整。
echo `awk -v x=$a -vy=$b 'BEGIN{print x+y }'`
[root@localhost sub_str]#
[root@localhost sub_str]# sh calculationtestawk.sh 1 3
4
[root@localhost sub_str]#
expr 还能检查变量是否为数字
标签:shell,sub,RANDOM,echo,数字,str,root,localhost,运算 From: https://www.cnblogs.com/xjianbing/p/17902803.html