我正在尝试使用转义双引号打印文件内容.
# read file contents from ${filename}
# - escape double quotes
# - represent newlines as '\n'
# print the result
echo "my file contents: \"${out}\""
Run Code Online (Sandbox Code Playgroud)
例如,如果我的文件是
<empty line>
console.log("hello, world");
<empty line>
Run Code Online (Sandbox Code Playgroud)
它应该打印
my file contents: "\nconsole.log(\"hello, world\");\n"
Run Code Online (Sandbox Code Playgroud)
我试图使用带有%q格式说明符的printf,但是它存在删除尾随空格的问题.