How can I write a heredoc to a file in Bash script?

前端 未结 9 1098
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 12:33

How can I write a here document to a file in Bash script?

9条回答
  •  误落风尘
    2020-11-22 12:56

    Instead of using cat and I/O redirection it might be useful to use tee instead:

    tee newfile <

    It's more concise, plus unlike the redirect operator it can be combined with sudo if you need to write to files with root permissions.

提交回复
热议问题