linux重定向多个文件,shell 多行重定向方法(多重嵌套)

这里讲的是多重嵌套。没用过 eof的朋友请参考其他基础贴

在自动化运维中,常常需要shell脚本。在自动化创建脚本时,会遇到脚本内容里有用eof重定向到配置文件的代码。

这样就不能用eof来创建脚本了,所以要多方法混用来实现自动化。

重定向方法1:

cat > /tmp/123.txt << eof

this is line 1 of the message.

this is line 2 of the message.

this is line 3 of the message.

this is line 4 of the message.

this is the last line of the message.

eof

重定向方法2:参考,有更多高级用法,纯英文网站,我目前双层嵌套就够用了。所以没多看。

cat > /tmp/123.txt << endofmessage

this is line 1 of the message.

this is line 2 of the message.

this is line 3 of the message.

this is line 4 of the message.

this is the last line of the message.

endofmessage

嵌套方法为:

cat > /server/scripts/test2.sh << endofmessage

cat >>/etc/sysctl.conf<

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

eof

endofmessage

#这样就创建了一个含有eof的脚本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值