An Interactive Spelling Checker
The UNIX spell program does an adequate job of catching spelling errors in a document. For most people, however, it only does half the job. It doesn’t help you correct the misspelled words. First-time users of spell find themselves jotting down the misspelled words and then using the text editor to change the document. More skilled users build a sed script to make the changes automatically.
The spellcheck program offers another way—it shows you each word that spell has found and asks if you want to correct the word. You can change each occurrence of the word after seeing the line on which it occurs, or you can correct the spelling error globally. You can also choose to add any word that spell turns up to a local dictionary file.
Before describing the program, let’s have a demonstration of how it works. The user enters spellcheck, a shell script that invokes awk, and the name of the document file.
spellcheck ch00Use local dict file? (y/n)
If a dictionary file is not specified on the command line, and a file named dict exists in the current directory, then the user is asked if the local dictionary should be used. spellcheck then runs spell using the local dictionary.
Running spell checker ...
Using the list of “misspelled” words turned up by spell, spellcheck prompts the user to correct them. Before the first word is displayed, a list of responses is shown that describes what actions are possible.
Responses: Change each occurrence, Global change, Add ...