To write the stdout of a command (in this case, echo hi) to a file, you can do:
echo hi > outfile
I would like a command instead of a redirection or pipe so that I do not need to invoke a shell. This is eventually for use with Ansible, which calls python's subprocess.POpen.
I am looking for:
stdout-to-file outfile echo hi
tee makes copying stdout to a file easy enough, but it accepts stdin, not a separate command.
Is there a common, portable command that does this? It's easy enough to write one, of course, but that's not the question. Ultimately, in Ansible, I want to do:
command: to-file /opt/binary_data base64 -d {{ base64_secret }}
Instead of:
shell: base64 -d {{ base64_secret }} > /opt/binary_data
Edit: Looking for a command available on RHEL 7, Fedora 21