是否可以在 unix bash 脚本中嵌套 Here Document? [英] Is nesting of Here Document possible in a unix bash script?

查看:28
本文介绍了是否可以在 unix bash 脚本中嵌套 Here Document?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在另一个 heredoc 中编写一个 heredoc?

Is it possible to write a heredoc within another heredoc ?

ssh -T -q yxz@server1 <<-"END_TEXT"
.
.
    ssh -T -q abc@server2 <<-"SUB_TEXT"
    .
    .
    SUB_TEXT
.
.
END_TEXT

推荐答案

但是,如果缩进是使用实际制表符完成的,则只有在缩进时才能识别嵌套的heredoc 终止符.空间不起作用.

Yes

However, the nested heredoc terminator will only be recognized when indented if the indentation is done with actual tabs. Spaces won't work.

所以你可能想要做一些更像:

So you probably want to do something more like:

ssh s1 << \eof1
  ssh s2 << \eof2
    hostname
eof2
eof1

这篇关于是否可以在 unix bash 脚本中嵌套 Here Document?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆