Created
January 28, 2020 23:46
-
-
Save SmugZombie/4d759877754c45fc4d79e94939f04f66 to your computer and use it in GitHub Desktop.
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 | |
| # Randomword.sh | |
| # Ron Egli - github.com/smugzombie | |
| WORDFILE=/usr/share/dict/words | |
| WORD= | |
| VALID=0 | |
| function randomword { | |
| RANDOM=$(date +%s%N); | |
| # echo $RANDOM | |
| # using cat means wc outputs only a number, not number followed by filename | |
| lines=$(cat $WORDFILE | wc -l); | |
| rnum=$((RANDOM*RANDOM%$lines+1)); | |
| WORD=$(sed -n "$rnum p" $WORDFILE); | |
| } | |
| function checkword { | |
| # echo "Running Checkword: $WORD" | |
| # Some entries may have 's, we dont want them in our output so invalidate and move on. | |
| if [[ $WORD == *"'"* ]]; then | |
| VALID=0 | |
| # echo "INVALID" | |
| else | |
| VALID=1 | |
| # echo "VALID" | |
| fi | |
| } | |
| randomword checkword while [ $VALID -eq 0 ]; do | |
| randomword | |
| checkword | |
| done | |
| echo $WORD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment