So, my collegue Sergej wanted to do an idempotent redirect to a file. He came up with this.
Awesome sauce!
Let's say you want to redirect the STDOUT of some command to a file (a config file for example) using the (bash) shell. In ideal case destination file should not be touched if it already has the exactly the same content you are going to write into it. How to do that in a single pipe?
Here's how:
echo "New contents" | diff -duaN "$target_path" - | patch --binary -s -p0 "$target_path"
Check out that link. pipe_debug()
and how it is used inside to_file()
is particularly sploosh-tastic! ;-)