按要求生成随机数 本文共有2631个字,关键词: ``` #!/bin/bash #Version:0.0.1 #Author:stone #Description:create random alpha & number. while :; do echo -n -e "\033[31;1mplease input row:\033[0m" read ROW row1=$(echo "$ROW" |sed 's/[0-9]//g') #将用户的输入进行过滤 if [ -z $ROW ]; then echo "the input cannot be empty." continue #输入不能为空 elif [ "$row1" == "" ]; then break #满足输入条件退出循环 else continue #不满足条件继续循环 fi done while :; do echo -n -e "\033[31;1mplease input column:\033[0m" read COLUMN column1=$(echo "$COLUMN" |sed 's/[0-9]//g') #将用户的输入进行过滤 if [ -z $COLUMN ]; then echo "the input cannot be empty." continue #输入不能为空 elif [ "$column1" == "" ]; then break #满足输入条件退出循环 else continue #不满足条件继续循环 fi done while :; do echo -n -e "\033[31;1mplease input descriptor:\033[0m" read DS ds1=$(echo "$DS" |sed -r 's/([0-9]|[a-z]|[[:space:]])//g') #将用户的输入进行过滤 ds2=$(echo "$DS" |sed 's/[[:space:]]//g') if [ -z $ds2 ]; then echo "the input cannot be empty." continue #输入不能为空 elif [ "$ds1" == "" ]; then break #满足输入条件退出循环 else continue #不满足条件继续循环 fi done num1=0 #用于数组下标 for i in {a..z}; do #将a-z放入数组 alphabet[${num1}]=$i let num1++ done num2=0 #用于数组下标 for j in {0..9}; do #将0-9放入数组 number[${num2}]=$j let num2++ done discription=($DS) #将每一列的描述符放入数组 for i in `seq 10`; do for R in $(seq $ROW); do # for C in $(seq $COLUMN); do #取消循环,在遍历数组时已达到要求 for D in ${discription[*]}; do CL=$(echo $D |wc -L) for CHAR in $(seq $CL); do CH=$(echo "$D" |cut -c ${CHAR}) alpha=$(($RANDOM%26)) #获取字母数组的随机下标 num=$(($RANDOM%10)) #获取数字数组的随机下标 alpha1=alphabet[$alpha] num3=number[$num] eval array1=$(echo \${$alpha1}) eval array2=$(echo \${$num3}) echo "$CH" |grep "[[:digit:]]" > /dev/null if [ "$?" == "0" ]; then LINE="${LINE}${array2}" fi echo "$CH" |grep "[[:alpha:]]" > /dev/null if [ "$?" == "0" ]; then LINE="${LINE}${array1}" fi done LINE="${LINE} " done echo $LINE >> /tmp/${i}.txt unset LINE # done done done ``` 「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」 赞赏 × 几人行 (๑>ڡ<)☆谢谢老板~ 2元 5元 10元 50元 100元 任意金额 2元 使用微信扫描二维码完成支付 版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。 shell脚本 2017-03-19 评论 2422 次浏览