linux shell的here document用法(cat << EOF)
来源:互联网 发布:axure rp中文版 mac 编辑:程序博客网 时间:2024/05/17 10:28
- linux shell的here document用法(cat << EOF)什么是Here DocumentHere Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下cmd << delimiterHere Document Contentdelimiter它的作用就是将两个 delimiter 之间的内容(Here Document Content 部分) 传递给cmd 作为输入参数。比如在终端中输入cat << EOF ,系统会提示继续进行输入,输入多行信息再输入EOF,中间输入的信息将会显示在屏幕上。如下:fish@mangos:~$ cat << EOF> First Line> Second Line> Third Line EOF> EOFFirst LineSecond LineThird Line EOF注: >这个符号是终端产生的提示输入信息的标识符这里要注意几点EOF 只是一个标识而已,可以替换成任意的合法字符作为结尾的delimiter一定要顶格写,前面不能有任何字符作为结尾的delimiter后面也不能有任何的字符(包括空格)作为起始的delimiter前后的空格会被省略掉Here Document 不仅可以在终端上使用,在shell 文件中也可以使用,例如下面的here.sh 文件cat << EOF > output.shecho "hello"echo "world"EOF使用 sh here.sh 运行这个脚本文件,会得到output.sh 这个新文件,里面的内容如下echo "hello"echo "world"Here Document的变形delimiter 与变量在Here Document 的内容中,不仅可以包括普通的字符,还可以在里面使用变量,例如将上面的here.sh 改为cat << EOF > output.shecho "This is output"echo $1EOF使用sh here.sh HereDocument 运行脚本得到output.sh的内容echo "This is output"echo HereDocument在这里 $1 被展开成为了脚本的参数 HereDocument但是有时候不想展开这个变量怎么办呢,可以通过在起始的 delimiter的前后添加 " 来实现,例如将上面的here.sh 改为cat << "EOF" > output.sh #注意引号echo "This is output"echo $1EOF得到的output.sh 的内容为echo "This is output"echo $1<< 变为 <<-Here Document 还有一个用法就是将 '<<' 变为 '<<-'。 使用 <<- 的唯一变化就是Here Document 的内容部分每行前面的 tab (制表符)将会被删除掉,这种用法是为了编写Here Document的时候可以将内容部分进行缩进,方便阅读代码。
0 0
- linux shell的here document用法(cat << EOF)
- linux shell的here document用法(cat << EOF)
- linux shell 的here document 用法 (cat << EOF)
- linux shell的here document用法(cat << EOF)
- linux shell 的here document 用法 (cat << EOF)
- linux shell的here document用法(cat << EOF)
- linux shell的here document用法
- Here Document(cat<<EOF)不使用反斜杠转义的技巧
- Linux shell---Cat and EOF
- shell 操作之 read、cat 和 here document
- linux cat命令的<<EOF
- 《Advanced Bash-scripting Guide》学习(十四):HERE Document和cat <<EOF
- linux shell 下here document 文档
- Linux Shell HERE DOCUMENT 重定向
- Shell之Here Document
- Shell之Here Document
- Shell之Here Document
- Shell之Here Document
- 自定义 ViewGroup 支持无限循环翻页之一(重写 onLayout以及 dispatchDraw)
- md5算法
- Object 祖宗类方法的重写注意事项
- epoll和select区别
- Ubuntun 技巧
- linux shell的here document用法(cat << EOF)
- NCFS report层 /gui
- android webview缓存显示与管理
- 求1000以内所有偶数的和
- 博弈论一 [ 巴什博奕 ]
- 搭建rails开发环境(ruby2.1+rails4.1.6)
- Java制作jar包的几种方法
- 利用while语句求1000以内偶数的和
- Android开发软件安装与环境配置