by akkartik · 11y ago · 0 comments
$ echo hi |sponge y
over: $ echo hi > y
?> Unlike a shell redirect, sponge soaks up all its input before opening the output file. This allows constructing pipelines that read from and write to the same file.
$ echo 'foo' > foo
$ echo 'bar' > bar
$ cat foo bar > foo
cat: foo: input file is output file
$ cat foo
bar
vs $ echo 'foo' > foo
$ echo 'bar' > bar
$ cat foo bar | sponge foo
$ cat foo
foo
bar