#!/bin/bash set -f COUNT=10 MAX=8 MIN=4 NUM=4 CHARS=('!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '{' '}' '[' ']' ':' ';' '/' '?' '>' '<' ',' '.' '=' '-' '_' '+' '~') LIST='/usr/share/dict/words' function gen_pass(){ UPPER=0 ( echo $((RANDOM%99)) echo $((RANDOM%99)) i=$NUM while read word; do if [ $UPPER -eq 0 ] && [ $((RANDOM % $i)) -eq 0 ]; then word="$(echo ${word^^})" UPPER=1 fi echo -n $word echo ${CHARS[$((RANDOM % ${#CHARS[@]}))]} i=$(( $i - 1 )) done < <(sed -rn "/^[^']{$MIN,$MAX}$/p" "$LIST" |shuf|tail -${NUM}) ) |shuf|tr -d '\n' } function help() { cat << EOF Usage: $0 [OPTIONS] -h, --help Display this text -c, --count Number of passwords to generate (10) -M, --max-length Maximum length of words (8) -m, --min-length Minimum length of words (4) -n, --number Number of words per password (4) -l, --word-list Specify a different word list to use (/usr/share/dict/words) EOF } while [ $1 ]; do # update the help text when adding new options case $1 in -h|--help) help; exit;; -c|--count) COUNT=$2;shift 2;; -M|--max-length) MAX=$2;shift 2;; -m|--min-length) MIN=$2;shift 2;; -n|--number) NUM=$2;shift 2;; -l|--word-list) LIST=$2;shift 2;; *) break;; esac done for i in $(seq $COUNT); do echo $(gen_pass) done set +f