shell脚本学习(三)

1、在grep中, ^标记着单词的开始, $ 标记着单词的结束。

查看一个单词是否在linux自带的词典中,脚本如下:

 

#bin/sh

#文件名:checkword.sh

word=$1

grep "^$1$"  /usr/share/dict/american-english -q

if [ $? -eq 0 ]; then

     echo $word is a dictionary word;

else

     echo $word is not a dictionary word;

fi

 

2、echo -e 中 -e 表明echo 会解释转义序列。

例如:  echo -e "1\nhello\n"

           等于   1                      回车

                    hello                 回车

 

3、sed中的s表示替换(substitute)。

例如: comm a.txt b.txt -3 | sed 's/^\t//'

hbg@root:~/dl$ comm a.txt b.txt -3
apple
        carrot
        cookies
iron
silver
steel

hbg@root:~/dl$ comm a.txt b.txt -3 | sed 's/^\t//'
apple
carrot
cookies
iron
silver
steel

 

posted @ 2015-12-21 18:58  hbg-rohens  阅读(195)  评论(0编辑  收藏  举报