#!/bin/bash
#Usage:rand num
#产生顺序字符的函数,可参考:
#http://bbs.chinaunix.net/viewthread.php?tid=676397&extra=page%3D1
#略加修改即可 ^_^
#此处设定的是50位以内的,过多的话,或许有问题
#
[[ $# != 1 || $1 > 50 ]]&&{ echo "Usage ${0##/*} num";exit 1; }
array=(a b c d e f g h i j k l m n o p q r s t u v \
w x y z A B C D E F G H I J K L M N O P Q R S T U V\
W X Y Z 0 1 2 3 4 5 6 7 8 9)
dodo(){
echo -n ${array[$((RANDOM%${#array[@]}))]}
}
i=1
n=$1
while((i<=n));do
dodo
((i++))
done 2>/dev/null
echo
测试:
/home/lee#sh rand 10
tUG2M6kTfg
/home/lee#sh rand 15
MqNGlBcW7PQubAq
/home/lee#sh rand 40
5XUOqD3uuTGU66YPKYujmWMzrMabVJEyj49uMXW2
/home/lee#sh rand 50
ZC3epSgNkICWLgaYhLmMEO5lfywhC5cQdMYHpsYKo5cw3mMCCs
/home/lee#sh rand 51
Usage:rand num
/home/lee#sh rand 12dsf #此处没作过多的处理,一个重定向打发掉
/home/lee#sh rand sdf234
Usage:rand num
/home/lee#sh rand 12
PpmD58lKGEU0
|
|
|