# Here document inside a here document?

**URL:** <https://community.unix.com/t/here-document-inside-a-here-document/277286>\
**Category:** Shell Programming and Scripting\
**Created:** [November 12, 2010, 7:33pm UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286 "2010-11-12T19:33:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnanavati](https://community.unix.com/letter_avatar/mnanavati/32/6_22734026db12803ebb3e059622ac3534.png) [@mnanavati](https://community.unix.com/u/mnanavati)\
**Post date:** [November 12, 2010, 7:33pm UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/1 "2010-11-12T19:33:34Z")

</div>

Can we use a here document inside a here document?

Something like this

```nohighlight
ssh user@remotehost << REMOTE
   sudo vserver vsernamename enter << VSERVER
      perform actions on vserver.
VSERVER
REMOTE

```

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [November 12, 2010, 8:44pm UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/2 "2010-11-12T20:44:23Z")

</div>

what shell are you using?

---

<div class="post-metadata">

**Author:** ![mnanavati](https://community.unix.com/letter_avatar/mnanavati/32/6_22734026db12803ebb3e059622ac3534.png) [@mnanavati](https://community.unix.com/u/mnanavati)\
**Post date:** [November 12, 2010, 11:47pm UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/3 "2010-11-12T23:47:51Z")

</div>

Bash!

---

<div class="post-metadata">

**Author:** ![jlliagre](https://community.unix.com/letter_avatar/jlliagre/32/6_22734026db12803ebb3e059622ac3534.png) [@jlliagre](https://community.unix.com/u/jlliagre)\
**Post date:** [November 13, 2010, 4:06am UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/4 "2010-11-13T04:06:43Z")

</div>

```nohighlight
ssh user@remotehost '
   sudo vserver vsernamename enter << VSERVER
      perform actions on vserver.
VSERVER
'

```

---

<div class="post-metadata">

**Author:** ![mnanavati](https://community.unix.com/letter_avatar/mnanavati/32/6_22734026db12803ebb3e059622ac3534.png) [@mnanavati](https://community.unix.com/u/mnanavati)\
**Post date:** [November 14, 2010, 12:01am UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/5 "2010-11-14T00:01:27Z")

</div>

I tried this. It throws an error saying unexpected end of file.  
Error is thrown on line sudo vserver vservername enter ---- unexpected eof.

---

<div class="post-metadata">

**Author:** ![jlliagre](https://community.unix.com/letter_avatar/jlliagre/32/6_22734026db12803ebb3e059622ac3534.png) [@jlliagre](https://community.unix.com/u/jlliagre)\
**Post date:** [November 14, 2010, 4:58am UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/6 "2010-11-14T04:58:25Z")

</div>

This syntax works fine with me.  
sudo 1.7.0  
bash 4.0.28(1)  
Sun\_SSH\_1.5

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_22734026db12803ebb3e059622ac3534.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [November 14, 2010, 5:02am UTC](https://community.unix.com/t/here-document-inside-a-here-document/277286/7 "2010-11-14T05:02:01Z")

</div>

"VSERVER" the one on the last line:

Must be in column #1 -- ie., all the way left as far as possible.
