主要是随机生成密码
方法一:
function generate_passwd()
{
local arr=( a b c d e f g h i g 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 G 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)
#for i in {1...8}
for ((i=0;i<8;i++))
do
echo -n ${arr[$RANDOM % ${#arr[@]}]}
done
}
方法二:
function generate_random()
{
openssl rand -base64 10 | cut -c 1-10
}
测试代码:
function generate_passwd()
{
local arr=( a b c d e f g h i g 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 G 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)
#for i in {1...8}
for ((i=0;i<8;i++))
do
echo -n ${arr[$RANDOM % ${#arr[@]}]}
done
}
function generate_random()
{
openssl rand -base64 10 | cut -c 1-10
}
pass=$(generate_passwd)
echo "pass : $pass"
rand=$(generate_random)
echo "rand : $rand"