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. apt GPG error

    W: GPG error: http://extras.ubuntu.com trusty Release: The following signatures couldn't be verified ...

  2. Thymeleaf标签学习

    目录 Thymeleaf Thymeleaf的特点 SpringBoot与之整合 Thymeleaf常用语法 变量_变量案列 变量_动静结合 变量_ognl表达式的语法糖 变量_自定义变量 方法 方法 ...

  3. unless|until|LABEL|{}|last|next|redo| || |//|i++|++i

    #!/usr/bin/perl use strict; use warnings; $_ = 'oireqo````'; unless($_ =~ /^a/m){print "no matc ...

  4. javascript 的七种基本数据类型

    六种基本数据类型 undefined null string boolean number symbol(ES6) 一种引用类型 Object 为什么要引入 Symbol? ES5的对象中的属性名是字 ...

  5. Notes_STL_List_And_Map

    //Description: 使用STL遇到的问题 //Create Date: 2019-07-08 09:19:15 //Author: channy Notes_STL_List_And_Map ...

  6. android适配全机型悬浮框、视频APP项目、手势操作、Kotlin妹子App、相机图片处理等源码

    Android精选源码 图片滤镜处理,相机滤镜实时处理,相机拍照录制 android仿爱壁纸App更换壁纸效果源码 基于Kotlin+MVP+Retrofit+RxJava+Glide 等架构实现短视 ...

  7. [LC] 438. Find All Anagrams in a String

    Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...

  8. HashMap相关知识

    HashMap的工作原理是近年来常见的Java面试题.几乎每个Java程序员都知道HashMap,都知道哪里要用HashMap,知道Hashtable和HashMap之间的区别,那么为何这道面试题如此 ...

  9. 吴裕雄--天生自然 Hadoop大数据分布式处理:centos7修改系统时间、时区

    cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 修改完后需要重启.

  10. JSON — Java与JSON数据互转

    转换时Bean所要求的: 被转换的Bean必需是public的. Bean被转换的属性一定要有对应的get方法,且一定要是public的. Bean中不能用引用自身的this的属性,否则运行时出现et ...