Diff’ing a file against the output of a command
I was recently watching Gary Bernhardt from destroyallsoftware.com (great screencasts, btw) on doing diffs of diffs. I haven’t needed (nor wanted) to do diffs of diffs, but the tip came in handy when recently diffing a local file against command output.
I was working on moving an application from Heroku to Amazon EC2 and I needed to check to make sure my local .env file was the same as the heroku environment configs.
Piece of cake:
diff .env <(heroku config --shell)
<() provides the output of the inner subshell through a file descriptor that diff can read like any normal file and do its comparison. See?
# echo <(heroku config --shell) /dev/fd/63
You could pipe the command to a file then diff the two, but this is succinct and handy. I can also wrap it in a watch command and make changes in another window until the two are aligned.