I have two cases where I want to create a file with its contents supplied on standard input:
- I need to use
sudoto have the privileges to create a file.
- An application always invokes an (interactive) editor specified by
$EDITORto process this input further, but I want to pipe data from a program instead.
In the former case, I could use
echo test | sudo bash -c 'cat > test.txt', but in this as well as in the latter case I usually use
tee and direct
tee's standard output to
echo test | sudo tee test.txt > /dev/null
echo test | EDITOR=tee application > /dev/null
However, this does not only throw away
tee's standard output, but also (in the latter case)
application's. It would be preferable to be able to specifically suppress
tee's standard output, so that I could instantly notice if something else wrote to standard output.
Is there a utility on standard Linux distributions that will write standard input to the file specified as a command line argument and not output anything?