linux shell 脚本 EOF

EOF:end of file,通过EOF可以往文件里面一次输入多行

常见用法:

1、打印多行

[root@master ansible]# cat << EOF
> a
> b
> c
> EOF
a
b
c
[root@master ansible]#

2、往test.txt中输入多行

[root@master ansible]# cat << EOF > test.txt
> ciao tomorro
> are you ok
> EOF
[root@master ansible]# cat test.txt
ciao tomorro
are you ok

3、自定义EOF,比如hi

[root@master ansible]# cat << hi > hh.txt
> 6666
> 4444
> 23232
> hi
[root@master ansible]# cat hh.txt
6666
4444
23232

4、脚本

[root@master ansible]# cat test.sh
#!/bin/bash
cat > ./hello.txt << EOF
Today is a goodday.
I'm the highman.
EOF
[root@master ansible]# sh test.sh
[root@master ansible]# cat hello.txt
Today is a goodday.
I'm the highman.

5、磁盘分区脚本(fdisk),新建一个/dev/sdb4的分区

[root@master ansible]# cat fdisk.sh
#!/bin/bash
fdisk /dev/sdb << EOF
n
p
4

+30M
w
EOF
partprobe

需要注意:这里面都是 一步一步执行,如果应为一些没有想到的提示信息,操作将会失败

 

猜你喜欢

转载自blog.csdn.net/Man_In_The_Night/article/details/86650738