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

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

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

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 13:05

    When root permissions are required

    When root permissions are required for the destination file, use |sudo tee instead of >:

    cat << 'EOF' |sudo tee /tmp/yourprotectedfilehere
    The variable $FOO will *not* be interpreted.
    EOF
    
    cat << "EOF" |sudo tee /tmp/yourprotectedfilehere
    The variable $FOO *will* be interpreted.
    EOF
    

提交回复
热议问题