我正在运行以下一段 bash 代码:
cat << END_TEXT
_ _
| | | |
__ _| |__ ___ __| |
/ _` | '_ \ / __/ _` |
| (_| | |_) | (_| (_| |
\__,_|_.__/ \___\__,_|
END_TEXT
出现错误:
bash: command substitution: line 1: syntax error near unexpected token `|'
bash: command substitution: line 1: ` | '_ \ / __/ _'
最佳答案
无需转义反引号。只需使用引用的 here-doc 字符串作为:
cat <<-'END_TEXT'
_ _
| | | |
__ _| |__ ___ __| |
/ _` | '_ \ / __/ _` |
| (_| | |_) | (_| (_| |
\__,_|_.__/ \___\__,_|
END_TEXT
根据 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`
.
关于Bash 在使用反引号时提示 here-document 中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48745627/