使用 Ispell 在命令行中检查拼写
拼写

> 
> Ispell 可以帮助你在纯文本中消除超过 50 种语言的拼写错误。
> 
> 
> 


![](/data/attachment/album/201905/24/192644wqqv6d0lztmqoqyl.jpg)


好的拼写是一种技巧。它是一项需要时间学习和掌握的技能。也就是说，有些人从来没有完全掌握这种技能，我知道有两三个出色的作家就无法完全掌握拼写。


即使你拼写得很好，偶尔也会输入错字。特别是在最后期限前如果你快速敲击键盘，那就更是如此。无论你的拼写的是什么，通过拼写检查器检查你所写的内容总是一个好主意。


我用[纯文本](https://plaintextproject.online)完成了我的大部分写作，并经常使用名为 [Aspell](https://opensource.com/article/18/2/how-check-spelling-linux-command-line-aspell) 的命令行拼写检查器来完成这项工作。Aspell 不是唯一的工具。你可能还想要看下不错的 [Ispell](https://www.cs.hmc.edu/%7Egeoff/ispell.html)。


### 入门


自 1971 年以来，Ispell 就以各种形式出现过。不要被它的年龄欺骗。Ispell 仍然是一个可以在 21 世纪高效使用的应用。


在开始之前，请打开终端窗口并输入 `which ispell` 来检查计算机上是否安装了 Ispell。如果未安装，请打开发行版的软件包管理器并从那里安装 Ispell。


不要忘记为你使用的语言安装词典。我唯一使用的语言是英语，所以我只需下载美国和英国英语字典。你可以不局限于我的（也是唯一的）母语。Ispell 有[超过 50 种语言的词典](https://www.cs.hmc.edu/%7Egeoff/ispell-dictionaries.html)。


![Installing Ispell dictionaries](/data/attachment/album/201905/24/192706zznjmeyv1yyg42qn.png "Installing Ispell dictionaries")


### 使用 Ispell


如果你还没有猜到，Ispell 只能用在文本文件。这包括用 HTML、LaTeX 和 [nroff 或 troff](https://opensource.com/article/18/2/how-format-academic-papers-linux-groff-me) 标记的文档。之后会有更多相关内容。


要开始使用，请打开终端窗口并进入包含要运行拼写检查的文件的目录。输入 `ispell` 后跟文件名，然后按回车键。


![Checking spelling with Ispell](/data/attachment/album/201905/24/192707pkc089bjj0mjcabk.png "Checking spelling with Ispell")


Ispell 高亮了它无法识别的第一个词。如果单词拼写错误，Ispell 通常会提供一个或多个备选方案。按下 `R`，然后按下正确选择旁边的数字。在上面的截图中，我按了 `R` 和 `0` 来修复错误。


另一方面，如果单词拼写正确，请按下 `A` 然后移动到下一个拼写错误的单词。


继续这样做直到到达文件的末尾。Ispell 会保存你的更改，创建你刚检查的文件的备份（扩展名为 `.bak`），然后关闭。


### 其他几个选项


此示例说明了 Ispell 的基本用法。这个程序有[很多选项](https://www.cs.hmc.edu/%7Egeoff/ispell-man.html)，有些你*可能*会用到，而另一些你*可能永远*不会使用。让我们快速看下我经常使用的一些。


之前我提到过 Ispell 可以用于某些标记语言。你需要告诉它文件的格式。启动 Ispell 时，为 TeX 或 LaTeX 文件添加 `-t`，为 HTML 文件添加 `-H`，对于 groff 或 troff 文件添加 `-n`。例如，如果输入 `ispell -t myReport.tex`，Ispell 将忽略所有标记。


如果你不想在检查文件后创建备份文件，请将 `-x` 添加到命令行。例如，`ispell -x myFile.txt`。


如果 Ispell 遇到拼写正确但不在其字典中的单词，比如名字，会发生什么？你可以按 `I` 将该单词添加到个人单词列表中。这会将单词保存到 `/home` 目录下的 `.ispell_default` 的文件中。


这些是我在使用 Ispell 时最有用的选项，但请查看 [Ispell 的手册页](https://www.cs.hmc.edu/%7Egeoff/ispell-man.html)以了解其所有选项。


Ispell 比 Aspell 或其他命令行拼写检查器更好或者更快么？我会说它不比其他的差或者慢。Ispell 不是适合所有人。它也许也不适合你。但有更多选择也不错，不是么？




---


via: <https://opensource.com/article/19/5/spelling-command-line-ispell>


作者：[Scott Nesbitt](https://opensource.com/users/scottnesbitt) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
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](https://plaintextproject.online) and often use a command line spelling checker called [Aspell](https://opensource.com/article/18/2/how-check-spelling-linux-command-line-aspell) to do the deed. Aspell isn't the only game in town. You might also want to check out the venerable [Ispell](https://www.cs.hmc.edu/~geoff/ispell.html).

## 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. My only language is 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](https://www.cs.hmc.edu/~geoff/ispell-dictionaries.html).

![Installing Ispell dictionaries Installing Ispell dictionaries](https://opensource.com/sites/default/files/uploads/ispell-install-dictionaries.png)

## 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](https://opensource.com/article/18/2/how-format-academic-papers-linux-groff-me). 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.

![Checking spelling with Ispell Checking spelling with Ispell](https://opensource.com/sites/default/files/uploads/ispell-checking.png)

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](https://www.cs.hmc.edu/~geoff/ispell-man.html), 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](https://www.cs.hmc.edu/~geoff/ispell-man.html) 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?

## Comments are closed.