3 ms·
Don't most shells implement something like ">"? How is sponge an improvement on this?
by swiley 6y ago
Don't most shells implement something like ">"? How is sponge an improvement on this?
- pfarrell 6y agoIn the provided example % sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd It looks like this allows an in place modification to the same doc. If you used % sed "s/root/toor/" /etc/passwd | grep -v joey > /etc/passwd Bash will process the redirection first, then execute the commands in the pipe. So, it will have cleared out /etc/passwd with the non-appending redirection ">" before sed operates on it. You'd end up with a blank /etc/passwd file. (ymmv, I don't know how other shells would handle this) Sponge, it seems, would cause the pipe to allow the preceding commands to complete before it outputs.
- sigstoat 6y agoyou can sudo sponge, and not run the entire command with elevated privileges. (i'd welcome a method of doing that in zsh.)