On most distributions you can use tee
:
echo "task goes here" | cat - todo.txt | tee todo.txt
An alternative isThe moreutils
which have a nice tool called sponge
:
echo "task goes here" | cat - todo.txt | sponge todo.txt
tee
and sponge
will It'll "soak up" STDIN and then write to the file, which means you don't have to worry about temporary files and moving them around.
You can get moreutils
with many Linux distros, through apt-get install moreutils
, or on OS X using Homebrew, with brew install moreutils
.