使用 cat 将文本保存到指定文件
示例1 带变量写入字符串, 注意4 行写法
__func1() {_hello="hello"_world="world"cat >test.txt <<EOF你好 世界$_hello ${_world}EOFcat test.txt}__func1
输出
你好 世界hello world
示例2 纯文本写入
第三行中的 'EOF' 不管是 双引号还是单引号, 都只写入纯文本
__func2() {_hello="hello"_world="world"cat >test.txt <<'EOF'你好 世界$_hello ${_world}EOFcat test.txt}__func2
输出
你好 世界$_hello ${_world}
