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