2 ms·
In 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
by pfarrell 6y ago
In 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.