Linux 现在还没有能够直接判断单词是否为词典中的单词的命令,不过可以通过在字典文件中是否查得到来判断。
将以下代码保存或直接复制到 shell 中,回车执行即可。其中 “word” 为你要检测的单词,如果是则给出
"Yes, $wd is in the dictionary",不是则给出 "No, $wd is not in the dictionary!"
#!/bin/bash
wd="word"
if [[ -f /usr/share/dict/word ]]; then
dictionary=/usr/share/dict/words
else
dictionary=$(locate -b "\words" | head -n 1)
fi
if grep -wi $wd $dictionary &>/dev/null; then
echo "Yes, $wd is in the dictionary!"
else
echo "No, $wd is not in the dictionary!"
fi