將以下代碼保存或直接復制到 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