Here Document

1.广播,将信息发给所有用户

#! /bin/sh
wall << zzzzzzzzzzz23End
asdfsdfsdaf
E-mail yousdf
asdfsadfasdf
asdfdsf
zzzzzzzzzzz23End
exit 0

 

2.虚拟一个2行的虚拟文件

#! /bin/sh
E_BADARGS=65
if [ -z "$1" ]
then
   echo "Usage: `basename $0 ` filename"
   exit $E_BADARGS
fi

TARGEFILE=$1
vi $TARGEFILE<<xx123
i
This is line 1 of the example line.
This is line 2 of the example line.
^[ -----------ctrl+v,ESC
ZZ
xx123

exit 0

 

3.cat多行数据

#! /bin/sh
cat<<End-of-message
--------------------------------
This is line of 1 of the message.
This is line of 2 of the message.
This is line of 3 of the message.
This is line of 4 of the message.
This is line of 5 of the message.
This is line of 6 of the message.
---------------------------------
End-of-message

exit 0

 

4.使用参数替换的here document

#! /bin/sh
CMNLINEPARAM=1
if [ $# -ge $CMNLINEPARAM ]
then
  NAME=$1
else
  NAME="John Doe"
fi
RESPONDENT="the author of this fine script"
cat<<Endofmessage
 Hello,there,$NAME.
 Greetings to you,$NAME,from $RESPONDENT.
Endofmessage

exit 0

 

5.上传一个文件对到一个目录

#! /bin/sh
E_ARGERROR=65
if [ -z "$1" ]
then
  echo "Usage: `basename $0` Filename-to-upload"
  exit $E_ARGERROR
fi

Filename=`basename $1`
Server="ibiblio.org"
Directory="/incoming/Linux"
Password="yourpassword"
ftp -n $Server << End-of-Session
user anonymous "$Password"
binary
bell
cd $Directory
put "$Filename.lsm"
put "$Filename.tar.gz"
bye
End-of-Session

exit 0

 

6.关闭参数替换

#! /bin/sh
NAME="John Doe"
RESPONDENT="the author of this fine script"
cat <<'EndofMessge'
Hello,there,$NAME.
Greeting to you, $NAME,from $RESPONDENT.
EndofMessage

exit 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值