cat写入文件内容包含环境变量

之前用cat写入文件习惯用这样的命令:

1
2
3
cat << EOF > outputfile
this is content
EOF

但是,如果写入的内容包换环境变量的话,会进行解析

1
2
3
cat << EOF > outputfile
this is $content
EOF

解决方式是在 EOF 添加单引号或者双引号

1
2
3
cat > outputfile << 'EOF'
this is $content
EOF