5175 shaares
488 private links
488 private links
A here document is a block of text or code which is redirected to an interactive program or a command.
#!/bin/bash
Command <<MyUniqueLimitString
some text
some more text
MyUniqueLimitString
The above is equivalent to Command < tempfile.txt where the tempfile contains the text required.
EOF and END are often chosen as the MyUniqueLimitString but any string can be used as long as it does not appear within the here document text.
The - option to mark a here document limit string (<<-LimitString) will suppress leading tabs (but not spaces) in the output. This allows the use of indentation (with tabs) when writing here-documents in shell scripts making them more readable.
Here documents can also be used to supply values to variables or functions.