Shell脚本-简单获取8位随机密码

第一种:8位随机字符串,包含小写字母,数字

方法1:

#!/bin/bash
a=$(echo "$RANDOM" | md5sum | cut -b 1-8)
echo $a

方法2:

#!/bin/bash
a=`cat /proc/sys/kernel/random/uuid | cut -b 1-8`
echo $a

第二种:8位数随机数字

方法1:

#!/bin/bash
b=$(echo "RANDOM" | cksum | cut -b 1-8)
echo $b

方法2:

#!/bin/bash
b=$(date +%N | cut -b 1-8)
echo $b

第三种:自定义随机8位字符串

#!/bin/bash
ALL_STR=(0 1 2 3 4 5 6 7 8 9 q w e r t y u i o p l k j h g f d s a z x c v b n m Q W E R T Y U I O P L K J H G F D S A Z X C V B N M)
sum=''
for i in {1..8}
do
        EACH_NUM=$[RANDOM%62+1]
        passw=${ALL_STR[EACH_NUM]}
        sum=${sum}${passw}
done
echo $sum

 

你可能感兴趣的:(Shell,字符串,shell)