最近些自动化脚本的时候,需要创建默认文件。根据传入不同变量生成不同的文件,通过 shell EOF和cat可以写入多行文本。

通过shell写入多行文本

示例.gitignore文件通过shell 写入

cat<<EOF>.gitignore 
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
EOF