3 ms·
Why not write it to a different file
by antihero 5y ago
Why not write it to a different file
- dredmorbius 5y agocmd < somefile | somefile.tmp && mv somefile.tmp somefile Will read from somefile, and only replace the source if (and when) the pipleline exits successfully. Mind that this may still bite in interesting ways. But less frequently. You can also invoke tempfile(1) which is strongly recommended in scripts. https://www.unix.com/man-page/Linux/1/tempfile/ https://www.unix.com/man-page/Linux/1/tempfile/
- HellsMaddy 5y agoI was wondering what the difference between tempfile and mktemp was. At the bottom of the tempfile man page, it says: > tempfile is deprecated; you should use mktemp(1) instead.
- dredmorbius 5y agoI ... need to revisit that. Though I suspect you're right.