shell编程的一些例子5

1.here文档

here文档允许我们调用一个交互式程序;可以从脚本程序中输出大量的文本,从而不必echo每行

例子1:

#!/bin/bash

cat<<!DATA!

This is a simple use of the here document.This data is the 

input given to the above cat command

!DATA

 

其输出为:

This is a simple use of the here document.This data is the 

input given to the above cat command

 

例子2(与grep搜索命令的交互):

demo_dext 文件内容

#!/bin/bash

if [ $# -eq 0]

then

echo "Usage:$0 name"

exit 1

fi

user_input="$1"

grep -i $user_input<<!DIRECTORY!

John Doe   1234567   hahahah

David Nice  3248428   jjkjkll

Don Carr   8989897   jkdjasl

!DIRECTORY!

exit 0

 

执行:

$chmod u+x demo_dext

$./demo_dext John

John Doe   1234567   hahahah

 

 

posted @ 2013-11-28 20:01  枫月寒  阅读(164)  评论(0编辑  收藏  举报