Linux Shell Here Document
Here Document 是一种有特殊用处的代码块,他使用IO重定向的形式记录了一段临时的文本或交互命令,并且把这些文本或命令 依次的传递给一个程序或一个命令,作为他运行时的标准输入。
Here document的语法格式为
void@void-ThinkPad-E450:~/linuxShellArg$ command << delimiter
> document
> docuemnt
> document
> delimiter
bash把操作符<<看成输入指令,后面的delimiter是标识符开始和结束的标识符,bash会一直输出提示符>,用来等待用户输入数据,一直到用户输入第二个delimiter标识符为止,他表明输入结束。两个delimiter之间的数据都会作为command命令的标准输入。
标识符delimiter可以使用任意字符串,但是delimiter只能是一个词,中间不能有空格或Tab键。
Here document 经常o用在Shell脚本的帮助函数中,例如android的build/envsetup.sh
function hmm() {
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
- mma: Builds all of the modules in the current directory, and their dependencies.
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is:
EOF
T=$(gettop)
local A
A=""
for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
A="$A $i"
done
echo $A
}
在函数hmm()中通过here document显示了一些帮助信息,这里通过cat命令 把here document输出到屏幕上,且delimiter标识符使用了EOF。
Linux Shell Here Document的更多相关文章
- linux shell的here document用法(cat << EOF)
什么是Here Document?Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下cmd << delimiter Here Docu ...
- linux shell的here document用法
转载自: http://my.oschina.net/u/1032146/blog/146941 什么是Here Document?Here Document 是在Linux Shell 中的一种特殊 ...
- (转)linux shell 的here document 用法 (cat << EOF)
什么是Here Documen: Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下 cmd << delimiter Here Docu ...
- linux shell编程总结
linux shell编程总结 本周学习了unix/linux shell编程,参考的是<LINUX与UNIX Shell 编程指南>,David Tansley著:徐焱,张春萌等译,由机 ...
- linux shell基础语法
1.第一个Shell脚本 打开文本编辑器,新建一个文件,扩展名为sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好,如果你用php写shell 脚本,扩展名就用php好了. 输入一些代码 ...
- Linux shell下30个有趣的命令
Tips 原文作者:Víctor López Ferrando 原文地址:30 interesting commands for the Linux shell 这些是我收集了多年的Linux she ...
- (转) Linux Shell经典实例解析
原文:http://blog.csdn.net/yonggeit/article/details/72779955 该篇博客作为对之前Linux Shell常用技巧和高级技巧系列博客的总结,将以Ora ...
- Linux shell之重定向输入,输出
shell是一个命令解释器,它在操作系统的最外层,负责直接与用户对话,把用户的输入解释给操作系统,并处理各种各样的操作系统的输出结果,输出到屏幕返回给用户.这种对话方式可以是交互的方式(从键盘输入命令 ...
- Linux shell脚本基础学习详细介绍(完整版)二
详细介绍Linux shell脚本基础学习(五) Linux shell脚本基础前面我们在介绍Linux shell脚本的控制流程时,还有一部分内容没讲就是有关here document的内容这里继续 ...
随机推荐
- gitlab安装CI问题汇总
0.设置gitlab获取代码的存放位置 vim /etc/gitlab-runner/config.toml 1.unable to access http://gitlab-ci-token:xxx ...
- 树莓派OLED模块的使用教程大量例程详解
简介 Python有两个可以用的OLED库 [Adafruit_Python_SSD1306库]->只支持SSD1306 [Luma.oled库]->支持SSD1306 / SSD1309 ...
- Android View post 方法
解析View.post方法.分析一下这个方法的流程. 说起post方法,我们很容易联想到Handler的post方法,都是接收一个Runnable对象.那么这两个方法有啥不同呢? Handler的po ...
- 后期静态绑定在PHP中的使用
什么叫后期静态绑定呢?其实我们在之前的文章PHP中的static中已经说过这个东西了.今天我们还是再次深入的理解一下这个概念. 首先,我们通过一段代码来引入后期静态绑定这一概念: class A { ...
- 更改已安装的织梦dedecms系统数据库表前缀
1 修改之前我们先备份下数据,备份的操作过程是:网站后台------系统------数据库备份/还原-------然后按提交.默认保存的数据在data/backupdata目录下. 2 修改目录下da ...
- Docker系列(5)- 常用命令(1) | 帮助命令
帮助命令 [root@localhost ~]# docker version #显示docker的版本信息 [root@localhost ~]# docker info #显示docker的系统信 ...
- pycharm 增删改查 mysql数据库
1.pycharm创建mysql数据表######################################################import pymysql# 创建连接con = p ...
- 博客主题——element v2
主题预览 主题下载 gshang.element-v2.rar
- Python return self
在Python中,return self的作用为: Returning self from a method simply means that your method returns a refer ...
- 定要过python二级 第10套
第一部分 第一题 1. int* 字符串 =几个东西 2. 此题的最开始的疑惑 (1)01 02 03 怎么产生 for 循环 (2)<<< 这个怎么产生 (3)<这个&l ...