EOF本意是 End Of File,表明到了文件末尾。

使用格式基本是这样的: 
命令 << EOF
内容段
EOF
将“内容段”整个作为命令的输入。
你的代码里就是用cat命令读入整段字符串并赋值给list变量。
其实,不一定要用EOF,只要是“内容段”中没有出现的字符串,都可以用来替代EOF,只是一个起始和结束的标志罢了。 有个特殊用法不得不说:
: << COMMENTBLOCK
shell脚本代码段
COMMENTBLOCK
这个用来注释整段脚本代码。 : 是shell中的空语句。 例一:使用shell操作数据库
假设数据库的操作过程是这样
 $ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.1.-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A mysql> select * from user;
mysql> exit
Bye

要用shell脚本访问可以如下

 #!/bin/sh 

 mysql -u root <<EOF
use mysql
select * from user;
exit
EOF

例二:使用shell为数据库用户授权

 cat > /tmp/mysql_sec_script<<EOF
use mysql;
update user set password=password('$mysqlrootpwd') where user='root';
delete from user where not (user='root') ;
delete from user where user='root' and password='';
drop database test;
DROP USER ''@'%';
flush privileges;
EOF /usr/local/mysql/bin/mysql -u root -p$mysqlrootpwd -h localhost < /tmp/mysql_sec_script rm -f /tmp/mysql_sec_script

cat命令详解

用法:cat [选项]... [文件]...
将[文件]或标准输入组合输出到标准输出。

-A, --show-all 等于-vET
-b, --number-nonblank 对非空输出行编号
-e 等于-vE
-E, --show-ends 在每行结束处显示"$"
-n, --number 对输出的所有行编号
-s, --squeeze-blank 不输出多行空行
-t 与-vT 等价
-T, --show-tabs 将跳格字符显示为^I
-u (被忽略)
-v, --show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外
--help 显示此帮助信息并退出
--version 显示版本信息并退出

如果没有指定文件,或者文件为"-",则从标准输入读取。

示例:
cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。
cat 将标准输入的内容复制到标准输出。

Shell之Here Document的更多相关文章

  1. linux shell的here document用法(cat << EOF)

    什么是Here Document?Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下cmd << delimiter  Here Docu ...

  2. linux shell的here document用法

    转载自: http://my.oschina.net/u/1032146/blog/146941 什么是Here Document?Here Document 是在Linux Shell 中的一种特殊 ...

  3. (转)linux shell 的here document 用法 (cat << EOF)

    什么是Here Documen: Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下 cmd << delimiter Here Docu ...

  4. shell 的here document 用法 (cat << EOF) (转)

    什么是Here Document Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下 cmd << delimiter Here Docu ...

  5. Shell脚本中的交互式命令处理

    先贴代码: DATE=`date -d -1hour +%T` fileName=erver_`date -d now +%Y-%m-%d-%H%M%S`.txt cp /home/BLload_ba ...

  6. shell编程笔记(基本部分)

    1.变量 a.需要给变量赋值时,可以这么写: b.要取用一个变量的值,只需在变量名前面加一个$ ( 注意: 给变量赋值的时候,不能在"="两边留空格 ) c.然后执行 chmod ...

  7. shell 12输入输出重定向

    shell输入/输出重定向 unix系统命令从终端接受输入并将产生的输出发送回终端.命令读取输入的地方,成为标准输入,默认是终端:命令的输出,为标准输出,默认也是终端. command > fi ...

  8. GDB配置与.gdbinit的编写

    GDB配置与.gdbinit的编写 当 GDB(即 GNU Project Debugger)启动时,它在当前用户的主目录中寻找一个名为 .gdbinit 的文件:如果该文件存在,则 GDB 就执行该 ...

  9. 给JavaScript初学者的24条最佳实践

    ­.fluid-width-video-wrapper { width: 100%; position: relative; padding: 0 } .fluid-width-video-wrapp ...

随机推荐

  1. 曾经倍受年轻人追棒的Facebook为何如今却被称为“老年人社交网站”?

    一直以来,Facebook都被视为最受年轻人欢迎的社交媒体.毕竟此前在社交领域,能跟Facebook这一庞然巨物掰手腕的网站.应用几乎还没出现.但很显然,随着Instagram和Snapchat等新型 ...

  2. Monkey安装与配置教程

    一.JAVA环境的搭建 安装jdk1.8.0_221,完成环境变量的配置 然后再在系统变量中找到Path,添加%JAVA_HOME%\bin;,确定后,按win+r打开运行,输入cmd 在cmd窗口中 ...

  3. uboot 编译

    . 解包u-boot源码包(u-boot-2016.07) . 配置交叉编译器 根据内核编译里的步骤配置 . 编译uboot yum install ncurses* // ncurses是个终端的图 ...

  4. 通过java语言实现MD5加密

    通过java语言实现MD5加密public static String getMd5(String str) { try { MessageDigest md5 = MessageDigest.get ...

  5. python,winreg,获取当前系统的桌面绝对路径

    import winreg import os def main(): new_path = os.path.join(desktop_path(), 'aaa.xlsx') # 结果为:C:\\Us ...

  6. Codeforces Round #572 (Div. 1) 差E

    Codeforces Round #572 (Div. 1) A2 题意:给一棵树,带边权,互不相同且为偶数.每次操作是选两个叶子然后在路径上同时加一个数.初始边权全是0,求一个操作序列使得最终边权与 ...

  7. Traffic Network in Numazu

    Traffic Network in Numazu 题目描述 Chika is elected mayor of Numazu. She needs to manage the traffic in ...

  8. [LC] 112. Path Sum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  9. python多进程之IPC机制以及生产者消费者模型

    1.进程间通信(IPC机制) 第一种:管道 import subprocessres=subprocess.Popen('dir',shell=True, stdout=subprocess.PIPE ...

  10. Base64基础知识

    转载自百度百科:http://baike.baidu.com/link?url=tI0FbG-ALTTNhRsaQHWXqdVWQDCq4bwd5Xsc0m46M8DKZ5jJyVWnr3IvTprh ...