diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-26 01:21:38 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-26 01:28:10 -0500 |
commit | 6c22a135015a9e5f54050d5c73bbde0daee3538a (patch) | |
tree | adecbb7413149aed0d9ff593b56140bcc47aeb7f | |
parent | 12b695954ac2c34d9dba43081e7f852e31c2b3ec (diff) |
hangman-helper: avoid using a temporary file
-rw-r--r-- | hangman-helper.sh | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/hangman-helper.sh b/hangman-helper.sh index 1e65969..3ed1c17 100644 --- a/hangman-helper.sh +++ b/hangman-helper.sh @@ -14,13 +14,10 @@ word=$1 not=$2 flag=$3 -temp="$(mktemp --tmpdir "${0##*/}.XXXXXXXXXX")" -trap "rm -f -- $(printf '%q' "$temp")" EXIT - -grep -ix "$word" /usr/share/dict/words | grep -iv "['$not]" > "$temp" - -if [[ "$flag" = '-l' ]]; then - cat "$temp" | tr 'A-Z' 'a-z' | sed 's/\(.\)/\1\n/'g | sort | uniq -c | sort -n -else - cat "$temp" -fi +grep -ix "$word" /usr/share/dict/words | grep -iv "['$not]" | { + if [[ "$flag" = '-l' ]]; then + tr 'A-Z' 'a-z' | sed 's/\(.\)/\1\n/'g | sort | uniq -c | sort -n + else + cat + fi +} |