Skip to content

Instantly share code, notes, and snippets.

@StudioEtrange
Created January 28, 2021 02:22
Show Gist options
  • Save StudioEtrange/992610a2d7f783ffe19b5e6396e70126 to your computer and use it in GitHub Desktop.
Save StudioEtrange/992610a2d7f783ffe19b5e6396e70126 to your computer and use it in GitHub Desktop.
inject file inline to command with heredoc
# https://stackoverflow.com/a/38731052
# variable substitution, leading tab retained, overwrite file, echo to stdout
tee /path/to/file <<EOF
${variable}
EOF
# no variable substitution, leading tab retained, overwrite file, echo to stdout
tee /path/to/file <<'EOF'
${variable}
EOF
# variable substitution, leading tab removed, overwrite file, echo to stdout
tee /path/to/file <<-EOF
${variable}
EOF
# variable substitution, leading tab retained, append to file, echo to stdout
tee -a /path/to/file <<EOF
${variable}
EOF
# variable substitution, leading tab retained, overwrite file, no echo to stdout
tee /path/to/file <<EOF >/dev/null
${variable}
EOF
# the above can be combined with sudo as well
sudo -u USER tee /path/to/file <<EOF
${variable}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment