The /usr/share/dict/ directory contains some of the dictionary files. Dictionary files are
text files that contain a list of dictionary words. We can use this list to check whether a word is a dictionary word or not.
#!/bin/bash
#Filename: checkword.sh
word=$1 #$0 是bash命令的名字,在本例是checkword.sh ,$1 是输入的第一个参数ful,$2是第二个,依次类推
echo $word is a dictionary word;
else
echo $word is not a dictionary word;
fi
The usage is as follows:
$ ./checkword.sh ful
ful is not a dictionary word
$ ./checkword.sh fool
fool is a dictionary word
text files that contain a list of dictionary words. We can use this list to check whether a word is a dictionary word or not.
$ ls /usr/share/dict/
注意:下面的内容跟linux的不同系统有关系的,需要到该目录下查看存放单词的文件名:
在我系统为: linux.words words
我系统版本为:
[elbort@elbort proc]$ cat version
Linux version 3.3.7-1.fc16.i686.PAE
#!/bin/bash
#Filename: checkword.sh
word=$1 #$0 是bash命令的名字,在本例是checkword.sh ,$1 是输入的第一个参数ful,$2是第二个,依次类推
grep "^$1$" /usr/share/dict/linux.words -q # "^$1$" 这个是重点, "^"是开头的意思,"$"是结尾的意思,整个结合就是只能是$1这个单词,前面和后面都没其他字母,在本例中ful 是不能和 beautiful 区配的
if [ $? -eq 0 ]; thenecho $word is a dictionary word;
else
echo $word is not a dictionary word;
fi
The usage is as follows:
$ ./checkword.sh ful
ful is not a dictionary word
$ ./checkword.sh fool
fool is a dictionary word