回显巨大的文本,给出参数列表太长的错误

回显巨大的文本,给出参数列表太长的错误

努力将巨大的文本(大约 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

相关内容