Indenting here documents
suggest changeYou can indent the text inside here documents with tabs, you need to use the <<-
redirection operator instead of <<
:
$ cat <<- EOF
This is some content indented with tabs `\t`.
You cannot indent with spaces you __have__ to use tabs.
Bash will remove empty space before these lines.
__Note__: Be sure to replace spaces with tabs when copying this example.
EOF
This is some content indented with tabs _\t_.
You cannot indent with spaces you __have__ to use tabs.
Bash will remove empty space before these lines.
__Note__: Be sure to replace spaces with tabs when copying this example.
One practical use case of this (as mentioned in man bash
) is in shell scripts, for example:
if cond; then
cat <<- EOF
hello
there
EOF
fi
It is customary to indent the lines within code blocks as in this if
statement, for better readability. Without the <<-
operator syntax, we would be forced to write the above code like this:
if cond; then
cat << EOF
hello
there
EOF
fi
That’s very unpleasant to read, and it gets much worse in a more complex realistic script.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents