Re: [dev] situ — change files in situ

From: Truls Becken <truls.becken_AT_gmail.com>
Date: Fri, 13 Apr 2012 20:40:14 +0200

On Fri, Apr 13, 2012 at 19:50, Strake wrote:

>> There is also sponge from http://kitenet.net/~joey/code/moreutils/
>
> which would also corrupt file on failure, by what little documentation
> I can read through the markup.

You are right. I thought that since it only opens the output file
after stdin is fully consumed, it would not touch the file on failure.
The test below reveals that sponge leaves the file alone if the
process is interrupted before end of stdin, but not if a program
before it in the pipe returns non-zero.

I guess I should test programs before suggesting them to others.

-Truls

$ echo TEST > tst
$ (sed s/ES/se tst; sleep 10) | sponge tst
sed: -e expression #1, char 7: unterminated `s' command
^C
$ cat tst
TEST
$ sed s/ES/se tst | sponge tst
sed: -e expression #1, char 7: unterminated `s' command
$ wc tst
0 0 0 tst
$
Received on Fri Apr 13 2012 - 20:40:14 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 13 2012 - 20:48:03 CEST