Here文档

Here文档为需要输入的程序,例如,mail、sort和cat等接收在线文本,直到遇到用户定义的结束符号为止。最常用的用户是在Shell脚本中和case命令一起创建菜单、自动登录等等。

1、建立菜单

cb@cb-K43SV:~$ cat herein.sh
while true
do
cat<<- ENDIF                         #<<-忽略制表符TAB
     1)linux
     2)xterm
     3)sun 
  4)quit
ENDIF
read choice
case "$choice" in
1)
TERM=linux
export TERM
;;
2)
TERM=xterm
export TERM
;;
3)
TERM=SUN
export TERM
;;
4)
break;;
esac
done

2、自动登录

cb@cb-K43SV:~$ cat login.sh
#!/bin/bash
ftp -v -n ftp.pku.edu.cn<<-END
user anonymous myaccount@myhost.com
ls
get welcome.msg
quit
END

3、其它

cb@cb-K43SV:~$ sort -n <<END
> hello
> world
> chenbin
> panda
> END
chenbin
hello
panda
world 

=-=-=-=-=
Powered by Blogilo

原文地址:https://www.cnblogs.com/pandachen/p/4567783.html