blob: 5bb4ddcc834701cb7df6c3c807af00ac9e9a795a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/bin/bash
set -e
set -u
usage() {
echo "Usage: $0 [-d <dictionary] [count]"
}
dictionary=american-english
while getopts "hd:" OPTION; do
case "$OPTION" in
h)
usage
exit 0
;;
d)
dictionary="$OPTARG"
;;
*)
usage >&2
exit 1
esac
done
shift $(($OPTIND - 1))
count=${1:-6}
if ! [[ $dictionary == *"/"* ]]; then
dictionary=/usr/share/dict/"$dictionary"
fi
if ! [ -e "$dictionary" ]; then
echo >&2 "$dictionary does not exist"
exit 1
fi
egrep '^[a-z]{1,6}$' "$dictionary" | shuf | head -n "$count" | tr '\n' '.' | sed -e 's/\.$//'
echo
|