Created
January 29, 2013 03:38
-
-
Save mpapi/4661609 to your computer and use it in GitHub Desktop.
Generates a random password, after http://xkcd.com/936/.
This file contains hidden or 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
#!/bin/bash | |
# | |
# Generates a random password, after http://xkcd.com/936/. | |
# | |
# -f [words file, one per line; default /usr/share/dict/words] | |
# -w [number of words; default 3] | |
# -n [min number of characters per word; default 6] | |
# -x [max number of characters per word; default 10] | |
# | |
set -u -e | |
WORDS=/usr/share/dict/words | |
NUM_WORDS=4 | |
MIN_CHARS=6 | |
MAX_CHARS=10 | |
while getopts f:w:n:x: OPTION | |
do | |
case ${OPTION} in | |
f) WORDS=${OPTARG};; | |
w) NUM_WORDS=${OPTARG};; | |
n) MIN_CHARS=${OPTARG};; | |
x) MAX_CHARS=${OPTARG};; | |
esac | |
done | |
egrep "^[a-z]{${MIN_CHARS},${MAX_CHARS}}\$" ${WORDS} \ | |
| shuf -n${NUM_WORDS} | xargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment