Skip to content

Instantly share code, notes, and snippets.

@iziang
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iziang/6f042ba1dc4ae7fd05c9 to your computer and use it in GitHub Desktop.
Save iziang/6f042ba1dc4ae7fd05c9 to your computer and use it in GitHub Desktop.
生成随机的密码,支持长度自定义
#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