O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 usage
					if (($# < 1 || $# > 2))
					then
					print "Usage: $0 pattern [file]"
					exit 1
					fi
					# Check/set DICT to word dictionary
					: ${DICT:=${2:-/usr/dict/words}}
					# Open $DICT for input
					exec 0<$DICT
					# Read each word into WORD
					while read WORD
					do
					# 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 - $WORD
					done
				

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required