Conclusions
This article discussed how to use the Heredoc in Shell Scripting. We discussed some of the commonly used delimiters with the Heredoc. Then, we explored all other possibilities of using a Heredoc in a shell script with extensive examples.
How to Use Heredoc in Shell Scripting
The Heredoc or Here Document is an input literal used by many programming and scripting languages. The Heredoc was originally used in UNIX Shells and is in fashion till date and, is supported by all popular Linux shells such as zsh, bash, tsh, etc. The symbol for a Heredoc is ‘<<‘ two left chevrons.
Syntax
<< 'Delimiter' ---statements/comments--- 'Delimiter'
A Heredoc is followed by a delimiter token, which in turn is followed by a content block. The block ended with the same delimiter token.
There are various delimiters that can be used such as BLOCK COMMENT, etc. In this article, we shall discuss some of the major and commonly used delimiter tokens.