I'm running the following piece of bash code:
cat << END_TEXT
_ _
| | | |
__ _| |__ ___ __| |
/ _` | '_ \ / __/ _` |
| (_| | |_) | (_| (_| |
\__,_|_.__/ \___\__,_|
END_TEXT
and am getting an error:
bash: command substitution: line 1: syntax error near unexpected token `|'
bash: command substitution: line 1: ` | '_ \ / __/ _'
No need to escape backticks. Just use quoted here-doc string as:
cat <<-'END_TEXT'
_ _
| | | |
__ _| |__ ___ __| |
/ _` | '_ \ / __/ _` |
| (_| | |_) | (_| (_| |
\__,_|_.__/ \___\__,_|
END_TEXT
As per man bash
:
If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence
\<newline>
is ignored, and\
must be used to quote the characters\
,$
, and`
.
It's the backticks. Most content in a here-document is not intrepreted and used as-is, but backticks change this.
The solution: Escape them, even though it messes up the layout of your script:
cat << END_TEXT
_ _
| | | |
__ _| |__ ___ __| |
/ _\` | '_ \ / __/ _\` |
| (_| | |_) | (_| (_| |
\__,_|_.__/ \___\__,_|
END_TEXT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With