linux shell 脚本 EOF

148 篇文章 2 订阅

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

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

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值