Shell之Here Document
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的更多相关文章
- 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 ...
- shell 的here document 用法 (cat << EOF) (转)
什么是Here Document Here Document 是在Linux Shell 中的一种特殊的重定向方式,它的基本的形式如下 cmd << delimiter Here Docu ...
- Shell脚本中的交互式命令处理
先贴代码: DATE=`date -d -1hour +%T` fileName=erver_`date -d now +%Y-%m-%d-%H%M%S`.txt cp /home/BLload_ba ...
- shell编程笔记(基本部分)
1.变量 a.需要给变量赋值时,可以这么写: b.要取用一个变量的值,只需在变量名前面加一个$ ( 注意: 给变量赋值的时候,不能在"="两边留空格 ) c.然后执行 chmod ...
- shell 12输入输出重定向
shell输入/输出重定向 unix系统命令从终端接受输入并将产生的输出发送回终端.命令读取输入的地方,成为标准输入,默认是终端:命令的输出,为标准输出,默认也是终端. command > fi ...
- GDB配置与.gdbinit的编写
GDB配置与.gdbinit的编写 当 GDB(即 GNU Project Debugger)启动时,它在当前用户的主目录中寻找一个名为 .gdbinit 的文件:如果该文件存在,则 GDB 就执行该 ...
- 给JavaScript初学者的24条最佳实践
.fluid-width-video-wrapper { width: 100%; position: relative; padding: 0 } .fluid-width-video-wrapp ...
随机推荐
- spring自定义aop
package com.dhht.config.articleAdvice; import com.dhht.util.UUIDUtil;import lombok.extern.slf4j.Slf4 ...
- 树莓派切换到root用户
1:如何修改pi账号密码 passwd pi 2:开启root账户 树莓派使用的linux是debian系统,所以树莓派启用root和debian是相同的 debian里root账户默认没有密码,但账 ...
- 线程池-进程池-io模型
一.线程池与进程池 什么是池?简单的说就是一个容器,一个范围 在保证计算机硬件安全的情况下最大限度的充分利用计算机, 池其实是降低了程序的运行效率,但是保证了计算机硬件的安全,也是实现了一个并发的效果 ...
- Spring-security整理
出于某些原因,需要学习一下spring的安全框架.(研究半天,如果单单说用户认证和授权这块儿,我感觉还是shiro好用.) spring security介绍可以参考一下以下文档: (满满的羡慕啊)我 ...
- [LC] 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- TensorFlow 介绍
关于 TensorFlow TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操作,图中的线(edges)则表示 ...
- worship|spurs|drowns out|frauds|expell|spray with|deposit|moist|gave a sigh
to have or show a strong feeling of respect and admiration for God or a god 敬奉,崇拜,信仰(上帝或神) On the is ...
- python学习笔记(6)数据类型-集合
集合(set)是一个无序的不重复元素序列. 可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典. 创建格 ...
- python学习笔记(5)数据类型-字典
字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中 ,格式如下所示: d ...
- [LC] 116. Populating Next Right Pointers in Each Node
You are given a perfect binary tree where all leaves are on the same level, and every parent has two ...