本文是个人学习了https://juejin.im/post/5b06578f51882538c150744b#heading-3
该文后,对其进行的一些完善。
ramdomString函数:
#原方法:
ramdomString()
{
#生成随机的16位字符串
openssl rand -base64 64 | tr -cd 'a-zA-Z' |head -c 16
}
#新方法:
ramdomString()
{
#生成随机单词组成的字符串
filepath=/usr/share/dict/words
totalWordsNum=`wc -l $filepath | awk '{print $1}'`
confuseString="lf_"
#索引初始值
idx=1
#NUM为要生成的随机单词的个数
NUM=3
declare -i num
declare -i randNum
ratio=37
while [ "$idx" -le "$NUM" ]
do
a=$RANDOM
num=$(( $a*$ratio ))
randNum=`expr $num%$totalWordsNum`
#单次生成的单词
contentString=`sed -n "$randNum"p $filepath`
if [ $idx -gt 1 ]
then
#首字母大写
firstLetter=$(echo ${contentString: 0: 1} | tr 'a-z' 'A-Z')
contentString=${firstLetter}${contentString: 1}
else
#首字母小写
firstLetter=$(echo ${contentString: 0: 1} | tr 'A-Z' 'a-z' )
contentString=${firstLetter}${contentString: 1}
fi
confuseString=${confuseString}${contentString}
#索引值加1
idx=`expr $idx + 1`
done
echo $confuseString
}
取值方式也相应改变
原取值方式:
ramdom=`ramdomString`
新取值方式:
ramdom=$(ramdomString)
上一张class-dump反编译之后的效果图
![](https://img.haomeiwen.com/i2245413/273abcffd2071204.png)
补充:
若遇到xxx.sh permission denied
可以执行
chmod a+x xxx.sh
网友评论