On 9/3/19, Greg Wooledge <wool...@eeg.ccf.org> wrote: > On Sat, Aug 31, 2019 at 06:28:15PM +0200, to...@tuxteam.de wrote: >> Me too, I didn't know about sponge. Small, nifty utility, doing one >> thing -- pretty Unixy. > > Oh god, no. Don't use sponge unless you enjoy data loss.
Nope - don't enjoy data loss at all. > See <https://mywiki.wooledge.org/BashPitfalls#pf13>. Just out of curiosity, sed 's/foo/bar/g' file > tmpfile && sync && mv tmpfile file seems to be the 'more correct' version of sed 's/foo/bar/g' file > tmpfile && mv tmpfile file Do you ever take it that far or is the "slight risk of data loss in case of a system crash / power loss" so slight that you don't bother? for whatever it's worth, if I was looking at the line sed 's/foo/bar/g' file > tmpfile && mv tmpfile file and trying to come up with all the ways it could fail, I'd change it to /bin/sed 's/foo/bar/g' file > tmpfile && /bin/mv tmpfile file so this wouldn't happen $ sed -e 's/$/\//' file > tmpfile && mv tmpfile file mv: overwrite 'file'? but it would have never occurred to me that I needed a sync before the mv Thanks, Lee