![回显巨大的文本,给出参数列表太长的错误](https://linux22.com/image/129444/%E5%9B%9E%E6%98%BE%E5%B7%A8%E5%A4%A7%E7%9A%84%E6%96%87%E6%9C%AC%EF%BC%8C%E7%BB%99%E5%87%BA%E5%8F%82%E6%95%B0%E5%88%97%E8%A1%A8%E5%A4%AA%E9%95%BF%E7%9A%84%E9%94%99%E8%AF%AF.png)
努力将巨大的文本(大约 500 KB)输出到 Linux 上的文件中。文本包含空格、特殊字符和其他......出现错误 /bin/sh :参数列表太长
#!/bin/bash
txt="---huge text separated by line and containing special characters---"
echo $txt
或者
#!/bin/bash
txt="---huge text separated by line and containing special characters---"
echo $txt >> filename.txt
答案1
避免转义 " 和 ' 的解决方法是在查看脚本时保持输出可读:
cat >output <<textmarker
-构造示例:
#!/bin/bash
cat >filename.txt <<EOT
Your output-text starts here
Every new line or tab will be on the output too
"text0" 'text1' echo "Hello"
#Any other even huge text //
\n But Dollarsign and backslash have to be escaped
For example \$ and \\
your output-text ends with this marker, which had to be on a newline without whitespace
EOT