Hunspell spelling command line¶
Hunspell is the spell checker of LibreOffice, OpenOffice.org, Mozilla Firefox 3 & Thunderbird, Google Chrome, and it is also used by proprietary software packages, like macOS.
Extended support for language peculiarities; Unicode character encoding, compounding and complex morphology.
Improved suggestion using n-gram similarity, rule and dictionary based pronunciation data.
Morphological analysis, stemming and generation.
Hunspell is based on MySpell and works also with MySpell dictionaries.
C++ library under GPL/LGPL/MPL tri-license.
Install Hunspell Debian based system¶
$ sudo apt update $ sudo apt install hunspell
Fist let’s see what your default language is set to
$ env | grep LANGUAGE LANGUAGE=en_US
Check the spelling of a word¶
$ echo "Linux" | hunspell -a @(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0) *
Hunspell returned an * which means it found that word spelled correctly.
Check the spelling of my first name
$ echo "Bill" | hunspell -a @(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0) *
Yep, in the dictionary.
Let’s try my last name
$ echo "Fahrenkrug" | hunspell -a @(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0) # Fahrenkrug 0
Nope and has 0 options to offer
Adding a word to the personal dictionary¶
Prefixing a single word line with * (note there should be no space between word and prefix) will add that word to the user’s dictionary but only for the current hunspell session, since, as per the man page, only a new line suffixed with # will cause the the word to be saved to your personal dictionary file. The file is a hidden file in your home directory ~/.hunspell_en_US (or whatever your language is)
Now lets add my last name to my personal dictionary:
echo -e "*Fahrenkrug\n#" | hunspell -a @(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0) $ cat ~/.hunspell_en_US Fahrenkrug
My last name was added to my personal directory
How we try it again, but using lowercase only
$ echo "fahrenkrug" | hunspell -a @(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0) & fahrenkrug 1 0: Fahrenkrug
Ah, still spelled wrong, but gave me an option that is correct.
Let’s try with the correct spelling
$ echo "Fahrenkrug" | hunspell -a @(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0) *
Spelled correctly , returned an *, well the way I added it anyway. Which brings up a perfect point, garbage in garbage out, as the saying goes. Hunspell doesn’t check what you added, so make sure the spelling is correct before you add a word or Hunspell will think it is the correct spelling even if it is not.
Use a different Language¶
To use another language other than your other your default LANGUAGE environment variable :
You can hit the tab key to see all of your loaded dictionary’s. In this case I selected es_ then hit the tab, if you leave blank and hit tab it will show all available dictionary’s.
$ echo "beer" | hunspell -d es_ es_AR es_BO es_CL es_CO es_CR es_CU es_DO es_EC es_ES es_GT es_HN es_MX es_NI es_PA es_PE es_PR es_PY es_SV es_US es_UY es_VE billf@orion:~$ echo "beer" | hunspell -d es_MX Hunspell 1.7.0 & beer 7 0: bree, veer, beber, seer, leer, peer, bereber
No match on the spelling, but gave 7 optional choices.
$ echo "cerveza" | hunspell -d es_MX Hunspell 1.7.0 *
We got a match with cerveza.