The spell Command

One of the characteristics of the English written language is that its orthography (i.e., spelling) is complex and can be difficult to remember. This is in contrast to many languages (e.g., Spanish and German) for which the spelling of words is closely related to their pronunciation. Fortunately, technology has come to the rescue, and there are multiple ways to check and correct spelling on Linux and other Unix-like operating systems.

One of the simplest, and sometimes most convenient, of these spelling checkers is the spell command. Despite its lack of sophisticated features, it is still worth being aware of spell for several reasons, including (1) it is very easy to use, (2) it can be found on many Unix-like systems and (3) it is well suited for use with other commands linked by pipes (which are used to combine commands).

spell compares words typed in at the keyboard or the contents of a text file to those in a built-in dictionary file and then writes all of the words not in the dictionary (and, therefore, presumably misspelled) to standard output (which is the display screen by default).

On some systems spell is a stand-alone program, either the original version or the GNU clone. On others, such as Red Hat Linux 9, it is a shell script (i.e., a simple program) that launches a simplified version of another spelling checking program, aspell, which emulates the core function of spell.

spell displays each presumably misspelled word on a new line. In the case of the Red Hat version, the words are displayed in alphabetic order and each erroneous spelling is displayed only once, regardless of the number of times that it appears in the text. If multiple files are specified for checking, a single, alphabetized list of words is still generated.

spell's syntax is

spell [options] [file_name(s)]

The items in the square brackets are optional. When no file names are supplied as arguments (i.e., inputs), spell will read from standard input, which by default is text typed in at the command line.

For example, it can easily be determined whether the word desireable is spelled correctly by first entering at the command line the spell command, pressing the RETURN key, typing the word desireable, pressing RETURN again and then simultaneously press the CONTROL key and the d key. The output will look like the following:

$ spell

The word desireable is echoed (i.e., repeated by the system) because it is not in the system dictionary and is thus quite likely a spelling error. If the same procedure is repeated using desirable (i.e., omitting the second e), then it is not echoed, because it is in the system dictionary and is therefore the correct spelling. Thus, the screen would look like:

$ spell

spell can also be used with lists of words and sentences. For example, typing spell, pressing the RETURN key, typing the sentence   This is the storry abuot an operating system that went from baad to wurse,   pressing RETURN again, and finally simultaneously pressing the CONTROL key and the d key would produce the following output:

$ spell
This is the storry abuot an operating system that went from baad to wurse

To find any spelling errors in a file, all that is necessary to supply the name of the file as an argument after the command and any options. For example, the following will search for errors in a file named file1:

spell file1

spell can be used to check any number of files simultaneously by listing them all as arguments, for example:

spell file1 file2 file3

It is then a simple matter to correct the misspellings using a text editor (e.g., vi or gedit).

As is the case with other filters, the output of spell can be redirected from standard output using the standard output redirection operator, which is designated by a rightward facing angular bracket. For example, the following tells spell to check the spelling of all words in the first three files and write its output to file4 instead of to the display screen:

spell file1 file2 file3 > file4

The output of spell can also be further processed by using pipes to send it to other filters. For example, in the following example the output of spell is piped to grep (which is used to search for files and the contents of files) in order to display only those misspelled words in file5 that contain the sequence of letters com

spell file5 | grep com

The output could likewise be redirected to a file instead of to the display screen, such as to a new or existing file named file6:

spell file5 | grep com > file6

Although spell is very useful for checking text against the several tens of thousands of commonly used words in the English language that are included in the dictionary file, it does not do a good job of checking technical terminology, proper nouns (e.g., names of people, places and products) and slang.

Also, spell is not interactive. That is, it does not highlight misspelled words in a file and assist the user in correcting them one by one in the context of the text. However, this can be an advantage in some cases, particularly if the user merely wants to see a list of the potentially misspelled words in a file without having to go through and attempt to correct all of them.

Moreover, some of the useful features that come with the original version of spell are not found on the aspell emulation version. For example, the original Unix version has several options, including -b, which accepts UK spellings (e.g. labour, colour, centre), and -x, which displays every possible stem for each word. The original version also allows users to create their own supplementary dictionary files, which can be very useful for adding technical terms and proper nouns.

When more features are desired for a command line spelling checker than are available on the the aspell emulation version, the user should consider installing the original version of spell or its GNU clone or using a more sophisticated program such as aspell or ispell, both of which are interactive and allow the use of user-created dictionaries. aspell is better at making suggestions when a word is seriously misspelled, whereas ispell has the advantage that it can be used with numerous foreign languages.

This article was written using the gedit text editor on a Red Hat 9 Linux machine. spell was used to check the spelling after the final proofreading by the author, and it found several errors. Interestingly, the only word that was misspelled multiple times was the word misspell itself, which was spelled mispell.

Created June 1, 2004. Updated September 18, 2005.
Copyright © 2004 - 2005 The Linux Information Project. All Rights Reserved.