这里是文档和双反斜杠

sou*_*ser 4 bash shell

如果我在包含多个反斜杠'\\'的shell脚本中使用here文档,则shell会将其转换为单个反斜杠.我可以在不更改文本的情况下解决此问题吗?

$ cat <<EOF
> Print \\hello \\world
> EOF
Print \hello \world

Pau*_*ce. 10

引用这里的开头文档标记:

cat <<'EOF'
Print \\hello \\world
EOF
Run Code Online (Sandbox Code Playgroud)

  • http://www.gnu.org/software/bash/manual/bashref.html#Redirections 的第 3.6.6 节解释了*为什么*这个答案有效。 (2认同)