Last active
August 29, 2015 14:00
-
-
Save iziang/6f042ba1dc4ae7fd05c9 to your computer and use it in GitHub Desktop.
生成随机的密码,支持长度自定义
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Version 1 | |
read -p "please input the length of passwd: " p | |
list=(0 1 2 3 4 5 6 7 8 9 a b c d A B C D + -) | |
for i in $(seq $p); do | |
echo -n ${list[$RANDOM % ${#list[*]}]} | |
done | |
#Version 2 | |
read -p "please input the length of passwd: " p | |
list="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
while [ "${n:=1}" -le "$p" ]; do | |
pass="$pass${list:(($RANDOM%${#list})):1}" | |
let n+=1 | |
done | |
echo $pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment