Heredoc reference

  1. variable substitution, leading tab retained, overwrite file, echo to stdout
tee /path/to/file <<EOF
    ${variable}
EOF
  1. no variable substitution, leading tab retained, overwrite file, echo to stdout
tee /path/to/file <<'EOF'
    ${variable}
EOF
  1. variable substitution, leading tab removed, overwrite file, echo to stdout
tee /path/to/file <<-EOF
    ${variable}
EOF
  1. variable substitution, leading tab retained, append to file, echo to stdout
tee -a /path/to/file <<EOF
    ${variable}
EOF
  1. variable substitution, leading tab retained, overwrite file, no echo to stdout
tee /path/to/file <<EOF >/dev/null
${variable}
EOF
  1. the above can be combined with sudo as well
sudo -u USER tee /path/to/file <<EOF
${variable}
EOF

Reference: