4 ms·
sort is a bad example: to support sorting in-place, it has to know the file name. Pity the user who typed sort < bigfile > bigfile for said user just los
by marvy 10y ago
sort is a bad example: to support sorting in-place, it has to know the file name. Pity the user who typed
sort < bigfile > bigfile
for said user just lost a file.
- d0mine 10y agoA general solution is something like: $ sort "$name" | sponge "$name" Check whether: $ sort -o "$name" "$name" works with your version of the sort utility.
- shabble 10y agoThis has bitten me occasionally, even though I know the workarounds (tempfiles or pipe-consumers like sponge(1)). I'm wondering if there's any practical use for the behaviour, or if it's worth hacking a shell such that it produces a warning/interactive confirm prompt for it (or transparently buffers to DWIM maybe?)
- eichin 10y agoIt's pretty common to `set -o noclobber` in beginner dotfiles; doing deferred-open-if-exists is an interesting idea that would probably get a lot of resistance :-)