3 ms·
Wait, is sponge just another way to redirect to a file? What's the benefit of: $ echo hi |sponge y over: $ echo hi > y ?
by akkartik 12y ago
Wait, is sponge just another way to redirect to a file? What's the benefit of:
$ echo hi |sponge y
over:
$ echo hi > y
?
- sciurus 12y ago$ 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
- mraison 12y agoFrom the man page: > 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.
- akkartik 12y agoAh! That is indeed useful.