1:Linux下,在/usr/share/dict下包含了词典文件,检查一个单词是否在词典里:
#!/bin/bash #文件名:checkout.sh #检查给定的单词是否为词典中的单词 word=$1; grep "^$1$" /usr/share/dict/words -q if [ $? -eq 0 ];then echo "word is a dictionary word" else echo "word is not a dictionary word" fi
其中:grep 语句里,^匹配开头,$匹配结尾 -q 禁止输出,若没有-q,当在词典里时,会先输出单词
2:通过aspell来检查某个单词是否在词典中
#!/bin/bash #filename:aspellcheck.sh #用拼写检查命令aspell来检查某个单词是否在词典中 word=$1; #set -x output=`echo "$word" ` | aspell list if [ -z $output ];then echo "word is a dictionary" else echo "word is not a dictionary" fi ~
但是还有点问题:Error: No word lists can be found for the language "en_US". 还未解决