Imagine that you want to output multiple lines of text in Bash, or any shell script. Maybe it’s for a help string for a particularly convoluted shell script you’re writing. You could have a separate
echo command for each line. Or you could use the “here document“.
The “here document” construction takes the text between two delimiters and passes it, as if it were piped, to a command.
if [[$# == 0 ]] || [[ "$1" == "-h" ]]; then cat << EOF This is my help message. There are many like it but this one is mine. My help message is my best friend. EOF
All of the text, as written, with line breaks and spaces and all, get passed to
cat and your helpful formatted message is printed to the user.