我想知道如何实现以下内容:
test(){
cat>file<<'EOF'
abc
EOF
}
Run Code Online (Sandbox Code Playgroud)
非常感谢.
来自bash(1):
Run Code Online (Sandbox Code Playgroud)If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.
它说tab,在我的测试中,tab工作,但空间不:
#!/bin/bash
cat>file <<-END
hello
world
hello
END
echo done
Run Code Online (Sandbox Code Playgroud)
(所有这些缩进都是制表符;关于代码的四个前导空格标记的有趣之处在于,在渲染文本中也只显示四个空格.)