EOF适用场景:
命令行多行输出脚本包装类型配置文件
> Hello
> EOF
Hello
111
222
333
EOF
复制终端是这样的。
> 111
> 222
> 333
> EOF
回车后
111
222
333
444
555
666
EOF
查看1.txt内容
111
222
333
444
555
666
aaa
bbb
ccc
EOF
查看
aaa
bbb
ccc
111
222
333
a
输出:
$ cat 1.txt
111
222
333
cat > filename <<EOFcat << EOF > filename
123
456
789
EOF
查看
123
456
789
追加内容
abc
def
ghi
EOF
查看内容
123
456
789
abc
def
ghi
或者cat << EOF > /usr/local/mysql/my.cnf
[client]
port=3306
socket=/usr/local/mysql/var/mysql.sock
[mysqld]
port=3306
socket=/usr/local/mysql/var/mysql.sock
basedir=/usr/local/mysql/
datadir=/data/mysql/data
pid-file=/data/mysql/data/mysql.pid
user=mysql
bind-address=0.0.0.0
server-id=1
sync_binlog=1
log_bin=mysql-bin
[myisamchk]
key_buffer_size=8M
sort_buffer_size=8M
read_buffer=4M
write_buffer=4M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES?
port=3306
EOF
#!/bin/bash
fdisk ?/dev/sdb ?<<EOF
n
p
1
?
?
wq
EOF
?
/sbin/mkfs .ext4 ?/dev/sdb1 ?&& ? /bin/mkdir ?-p ?/data ?&& ?/bin/mount ?/dev/sdb1 ?/data
echo ?’LABEL=data_disk /data ext4 defaults 0 2′ ?>> ?/etc/fstab
SELECT foo, bar FROM db
WHERE foo=’baz’
EOF
)
$ echo -e “$sql”
#!/bin/bash
echo \$PWD
echo $PWD
EOF
查看内容
#!/bin/bash
echo $PWD
echo /home/user
> foo
> bar
> baz
> EOF
bar
baz
$ cat b.txt
bar
baz
{
? ?”exec-opts”: [“native.cgroupdriver=systemd”],
? ?”log-driver”: “json-file”,
? ?”log-opts”: {
? ?”max-size”: ?”100m”
? ? },
? ?”registry-mirrors”: [
? ? “https://hub-mirror.c.163.com”,
? ? “https://mirror.baidubce.com”
? ]
?}
?EOF
查看
{
“exec-opts”: [“native.cgroupdriver=systemd”],
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”
},
“registry-mirrors”: [
“https://hub-mirror.c.163.com”,
“https://mirror.baidubce.com”
]
}
How does “cat << EOF” work in bash?
What is Cat EOF in Bash Script?
到此这篇关于Bash EOF的使用小结的文章就介绍到这了,更多相关Bash EOF内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!