这里讲的是多重嵌套。没用过 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的脚本