查看某个字符串是否是一个英语单词

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.

$ ls /usr/share/dict/

注意:下面的内容跟linux的不同系统有关系的,需要到该目录下查看存放单词的文件名:     

在我系统为:   linux.words  words

我系统版本为:

[elbort@elbort proc]$ cat version
Linux version 3.3.7-1.fc16.i686.PAE


In order to check whether the given word is a dictionary word, use the following script:
#!/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 ]; then
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值