linux 拼写检查与词典操作

aspell命令作用是拼写检查, 目录/usr/share/dict包括了一些词典文件,如 american-english cracklib-small等,aspell检查单词是否在字典里。

  • 检查单词是否在字典里的脚本1
1
2
3
4
5
6
7
8
9
#!/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

-q 表示禁止grep产生输出内容;$1代表命令行第一个参数,$标记单词的结束

1
2
3
4
$ ./checkword.sh fu
fu is not a dictionary word
$ ./checkword.sh a
a is a dictionary word
  • 检查单词是否在字典里的脚本2
1
2
3
4
5
6
7
8
9
#!/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