Here document (heredoc) redirects a multiline string literal to the preceding command while preserving line breaks. Unix syntax for it is:
[command] <<DELIMITER
First line.
Second line.
Third line.
Fourth line.
DELIMITER
<< is Redirection Operator
- is optional Tab Suppression
DELIMITER - an arbitrary string, Delimiter Token; must be the same at the beginning and at the end
Appending a minus sign to the redirection operator <<- causes all leading tab characters to be ignored. This allows you to use indentation when writing heredocs in shell scripts. We can then indent both the here-doc and the delimiter with tabs (not spaces!):
#! /bin/bash
cat <<-EOF
indented
EOF
echo Done
---

No comments:
Post a Comment