Created
          October 14, 2011 11:13 
        
      - 
      
 - 
        
Save janmoesen/1286835 to your computer and use it in GitHub Desktop.  
    Word of the day in Bash
  
        
  
    
      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
    
  
  
    
  | # Read a random word from the dictionary and try to get its definition from | |
| # Merriam-Webster. | |
| function word-of-the-day { | |
| local file="${1:-/usr/share/dict/words}"; | |
| if ! [ -r "$file" ]; then | |
| echo "Cannot read from dictionary file: $file" 1>&2; | |
| return 1; | |
| fi; | |
| local IFS=$'\n' words=($(<"$file")); | |
| local num_words=${#words[@]}; | |
| # The silly math is to half-assedly compensate for $RANDOM's range being | |
| # from 0 to 32767, while there are many more words in the dictionary. | |
| local word="${words[$((($num_words / 32767 * $RANDOM) % $num_words))]}" | |
| echo "$word"; | |
| type -t lynx > /dev/null && \ | |
| lynx -width 1024 -nolist -dump "http://www.merriam-webster.com/wdictionary/$word" | \ | |
| awk '/^ *([a-z] )?:/ { sub(/[^:]*: /, "* "); print $0; }'; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment