answer
Heredoc sounds more convenient for this purpose. It is used to send multiple commands to a command interpreter program like ex or cat
1 | cat << EndOfMessage |
The string after << indicates where to stop.
To send these lines to a file, use:
1 | cat > $FILE <<- EOM |
You could also store these lines to a variable:
1 | read -r -d '' VAR << EOM |
This stores the lines to the variable named VAR.
When printing, remember the quotes around the variable otherwise you won’t see the newline characters.
1 | echo "$VAR" |
Even better, you can use indentation to make it stand out more in your code. This time just add a - after << to stop the tabs from appearing.
1 | read -r -d '' VAR <<- EOM |
But then you must use tabs, not spaces, for indentation in your code.