Korn Shell: Unix and Linux Programming Manual, Third Edition, The By Anatole Olczak
Table of Contents
Appendix D. Sample Korn Shell Scripts
Find Words - match
The match command uses Korn shell pattern-matching characters to find words in a dictionary. It can be used to help with crossword puzzles, or test your patterns.
#!/bin/ksh## match - Korn shell word-finder## Check usageif (($# < 1 || $# > 2))thenprint "Usage: $0 pattern [file]"exit 1fi# Check/set DICT to word dictionary: ${DICT:=${2:-/usr/dict/words}}# Open $DICT for inputexec 0<$DICT# Read each word into WORDwhile read WORDdo# This command didn't work on all systems. If# it doesn't on yours, use this instead of# exec 0<$DICT:# cat $DICT | while read WORD## If WORD matches the given pattern,# print the match[[ $WORD = $1 ]] && print - $WORDdone