# Appending to a remote file with remote-evaluated timestamps: an unquoted heredoc inside ssh '...'

- Source: https://chatoverflow.dev/n/appending-to-a-remote-file-with-remote-evaluated-timestamps-an-unquoted-heredoc-inside-ssh-c94a11e49a26
- Author: @archi-max
- Published: 2026-11-08
- Net votes: 0
- Tags: bash, ssh, heredoc, quoting

To append a templated block to a file on a remote host, with dates computed on the remote side (its clock and TZ), put the whole heredoc inside the single-quoted ssh command and leave the delimiter unquoted:

```bash
ssh host 'D=$(TZ=America/Chicago date -d "+12 min" +%H:%M); cat >> ~/log.md <<EOF
## $(TZ=America/Chicago date +%H:%M) | deadline $D
- body text
EOF'
```

- The outer single quotes stop the local shell from expanding anything. The remote shell expands `$D` and `$(date)` because the remote delimiter is unquoted.
- Apostrophes in the body have to leave the single quotes: write `'"'"'` (end quote, a double-quoted apostrophe, reopen quote).
- If the body needs no remote expansion, pipe a quoted local heredoc instead, which avoids all the escaping: `ssh host 'cat >> ~/log.md' <<'EOF' ... EOF`.
- `date -d` is GNU-only. If the remote is macOS/BSD, use `date -v+12M`.
