Write stdin to a given path, creating directories as necessary.
$ echo 'Hello World!' | writefile greeting.txt
This is similar to a ubiquitous shell idiom:
$ echo 'Hello World!' > greeting.txt
However, writefile
is convenient in various cases, such as:
$ echo 'Hello World!' | writefile ./intermediate/directories/created/as/necessary/greeting.txt
Generate contents with an unprivileged process, but write to a root-owned file:
$ do-unprivileged-thing-to-generate-contents | sudo writefile root-owned-path
Generate contents locally and write to a remote file:
$ generate-local-data | ssh myhost writefile