here文档

一种特殊的重定向

基本格式:

command << token
text
token
  • command是接受标准输入的命令名;
  • token是用来指示嵌入文本的结尾;
  • text文本内容;

注意:

  • token必须在一个单独的行中出现,且文本行的末尾无空格;
  • 在here文档中,引号失去其特殊含义;
  • <<- 忽略文本中的Tab字符;
  • << 'token'可忽略命令替换,使其不进行任何转移;

实例1:忽略制表符

cat <<- HELP

	该文件目的在于对镜像进行tar包转移。操作方法
	save.sh [appname1]-[version1] [appname2]-[version2]
	appname   -----   为镜像名字中的模块名称;
	version   -----   为镜像名字中的模块版本号;	
	打包结果为一个以日期为命名的tar包;

	默认镜像前缀为:”harbor.io:1180/szlt“,若要修改为其他的请进入文件修改变量”HARBOR_ADDRESS“的默认值

	eg:
	1. 对于镜像harbor.io:1180/aliyun/ucx:ec39fc1be7,使用方式为 save.sh ucx-ec39fc1be7
	2. 对于镜像harbor.io:1180/aliyun/ucx:ec39fc1be7,harbor.io:1180/aliyun/apg:d4fdb86ff0; 
	   使用方式为:save.sh ucx-ec39fc1be7 apg-d4fdb86ff0
	HELP

实例2:command可以是任何接受标准输入的命令

#!/bin/sh
sqlplus "Sdadmin/admin" <<eof
@SD_P_CreateSeparatetable.prc;
eof

实例3:写入文本,且忽略引号的作用

[root@ccod4 ~]# echo $USER
root
[root@ccod4 ~]# cat << eof > a.sh
> "hello word,$USER"
> 'hello word,$USER'
> 
> eof
[root@ccod4 ~]# 
[root@ccod4 ~]# 
[root@ccod4 ~]# cat a.sh
"hello word,root"
'hello word,root'

实例4:忽略命令替换

[root@ccod4 ~]# cat << 'eof' > a.sh
> "hello word,$USER"
> 'hello word,$USER'
> eof

[root@ccod4 ~]# 
[root@ccod4 ~]# cat a.sh
"hello word,$USER"
'hello word,$USER'

参考链接:
http://c.biancheng.net/view/3109.html

猜你喜欢

转载自blog.csdn.net/jjt_zaj/article/details/113055678