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的内容这里继续 ...
随机推荐
- go命令帮助
Go is a tool for managing Go source code. go-->管理go源码的工具-->管理工具,包含很多功能命令 Usage: go <command ...
- Lombok中@Data注解的坑
开发遇到@Data注解的大坑 如果使用@Data注解,会默认重写hashcode和equals方法 那会遇到什么问题呢? 比如说: @Data public class DataTest { priv ...
- 剑指offer计划19( 搜索与回溯算法中等)---java
1.1.题目1 剑指 Offer 64. 求1+2+-+n 1.2.解法 这题看评论区真的绝了,都是人才,各个说话都好听,我看到个还有用异常来结束的就离谱. 这题用了&&当左边为fal ...
- EcShop调用显示指定分类下的子分类方法
ECSHOP首页默认的只有全部分类,还有循环大类以及下面小类的代码,貌似没有可以调用显示指定大类下的子分类代码.于是就有这个文章的产生了,下面由夏日博客来总结下网站建设过程中ECSHOP此类问题的网络 ...
- Java基础系列(40)- Arrays类
Arrays类 数据的工具类java.util.Arrays 由于数组对象本身并没有什么方法可以供我们调用,但API中提供了一个工具类Arrays供我们使用,从而可以对数据对象进行一些基本的操作 查看 ...
- Jmeter系列(9)- Linux环境安装之安装JDK
step-1下载安装包 下载Linux环境下的jdk1.8,请去(官网)中下载jdk的安装文件:或者评论区留言 step-2解压到/usr/local目录 mkdir /usr/local/java ...
- requests接口自动化-列表与字典参数化
def server_ip(): # 配置文件,通过修改配置,在不同环境进行测试 # dev_ip='https://www.baidu.com/' # sit_ip='https://cn.bing ...
- 一文让你彻底理解SQL关联子查询
员工表的主要信息: 需求:检索工资大于同职位的平均工资的员工信息. 直觉的做法 员工多,而相应的职位(如销售员.经理.部门经理等)少,因此首先想到的思路是对职位分组,这样就能分别得到各个职位的平均工资 ...
- python之jsonpath
json 官方文档:http://docs.python.org/library/json.html JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使 ...
- springBoot 基础入门
来处:是spring项目中的一个子项目 优点 (被称为搭建项目的脚手架) 减少一切xml配置,做到开箱即用,快速上手,专注于业务而非配置 从创建项目上: -- 快速创建独立运 ...