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". 还未解决

 

相关文章:

  • 2022-12-23
  • 2021-10-21
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-05-22
猜你喜欢
  • 2022-12-23
  • 2021-12-25
  • 2021-05-04
  • 2021-08-11
  • 2022-02-22
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案