Check Your Spelling at the Command Line with Ispell
28 June, 2021
This post was originally published, in a slightly different form, at Opensource.com and appears here via a CC-BY-SA 4.0 license.
Good spelling is a skill. A skill that takes time to learn and to master. That said, there are people who never quite pick that skill up — I know a couple or three outstanding writers who can’t spell to save their lives.
Even if you spell well, the occasional typo creeps in. That’s especially true if you’re quickly banging on your keyboard to meet a deadline. Regardless of your spelling chops, it’s always a good idea to run what you’ve written through a spelling checker.
I do most of my writing in plain text and often use a command line spelling checker called Aspell to do the deed. Aspell isn’t the only game in town. You might also want to check out the venerable Ispell.
Getting Started
Ispell’s been around, in various forms, since 1971. Don’t let its age fool you. Ispell is still a peppy application that you can use effectively in the 21st century.
Before doing anything else, check whether or not Ispell is installed on your computer by cracking open a terminal window and typing which ispell. If it isn’t installed, fire up your distribution’s package manager and install Ispell from there.
Don’t forget to install dictionaries for the languages you work in, too. I’m more of a poly-not than a polyglot — I only work in English, so I just need to worry about grabbing the US and British English dictionaries. You’re not limited to my mother (and only) tongue. Ispell has dictionaries for over 50 languages.
Using Ispell
If you haven’t guessed already, Ispell only works with text files. That includes ones marked up with HTML, LaTeX, and nroff or troff. More on this in a few moments.
To get to work, open a terminal window and navigate to the directory containing the file where you want to run a spelling check. Type ispell followed by the file’s name and then press Enter.
Ispell highlights the first word it doesn’t recognize. If the word is misspelled, Ispell usually offers one or more alternatives. Press R and then the number beside the correct choice. In the screen capture above, I’d press R and 0 to fix the error.
If, on the other hand, the word is correctly spelled, press A to move to the next misspelled word.
Keep doing that until you reach the end of the file. Ispell saves your changes, creates a backup of the file you just checked (with the extension .bak), and shuts down.
A Few Other Options
This example illustrates basic Ispell usage. The program has a number of options, some of which you might use and others you might never use. Let’s take a quick peek at some of the ones I regularly use.
A few paragraphs ago, I mentioned that Ispell works with certain markup languages. You need to tell it a file’s format. When starting Ispell, add -t for a TeX or LaTeX file, -H for an HTML file, or -n for a groff or troff file. For example, if you enter ispell -t myReport.tex, Ispell ignores all markup.
If you don’t want the backup file that Ispell creates after checking a file, add -x to the command line — for example, ispell -x myFile.txt.
What happens if Ispell runs into a word that’s spelled correctly but isn’t in its dictionary, like a proper name? You can add that word to a personal word list by pressing I. This saves the word to a file called .ispell_default in the root of your /home directory.
Those are the options I find most useful when working with Ispell, but check out Ispell’s man page for descriptions of all its options.
Is Ispell any better or faster than Aspell or any other command line spelling checker? I have to say it’s no worse than any of them, nor is it any slower. Ispell’s not for everyone. It might not be for you. But it is good to have options, isn’t it?