Most Linux distributions contain a dictionary file, along with a aspell tool that is useful for spell checking
1, the directory/usr/share/dict/contains some dictionary files, "dictionary file" is a dictionary word list contains a text file, you can use this list to check whether a word is a word in the dictionary.
To check whether a given word belongs to a word in the dictionary, use the following script:
#!/bin/bash
#文件名: checkword.sh
Word=$1
grep "^$1$"/usr/share/dict/british-english-q
If [$?-eq 0]; Then
Echo $word is a dictionary word;
Else
Echo $word is not a dictionary word;
Fi
The syntax for this script is as follows:
./checkword.sh ful
Ful is not a dictionary word
./checkword.sh Feel
Ful is a dictionary word
Working principle
In grep, ^ marks the beginning of a word, and $ marks the end of the word.
-Q Disables the generation of any output
We can also use the spell checker command Aspell to check a word in the dictionary
#!/bin/bash
#文件名: aspellcheck.sh
Word=$1
Output= ' echo \ ' $word \ ' | Aspell List '
If [-Z $output];then
Echo $word is a dictionary word;
Else
Echo $word is not a dictionary word;
Fi
When the given input is not a dictionary word, the Aspell List command produces the output text, and conversely does not produce any output,-Z is used to confirm whether the $output is empty.
Lists all the words in the file that start with a specific word:
$look Word filepath
Or
$grep "^word" filepath
By default, if the file parameter is not given, the look command uses the default dictionary (/usr/share/dict/words) and returns the output.
$look Word
#像这样使用时, the Look command takes the default dictionary as the file parameter
2.14 Spell check and dictionary operation