[2013-06-25 20:22] Jakob Kramer <jakob.kra...@gmx.de>
> 
> I wrote a sponge program, but I am not fully convinced of it yet.  What
> do you think?

I think you shouldn't rename(2). Renaming a file and replacing it's
contents are quite different things. Take for example:

        $ mkdir a
        $ chmod 600 a/b

        $ touch a/b
        $ chmod 100 a

        $ echo foo >a/b    # this goes well

        $ echo bar >c
        $ mv c a/b    # this not
        mv: cannot move `c' to `a/b': Permission denied

Special permissions and owner/group-ships are lost as well.

Either keep the contents in memory or read-write the contents
back.

Or better use what's already available: sort(1).

        #!/bin/sh
        if $# -ne 1 ; then
                echo "Usage: ${0##*/} outfile" >&2
                exit 1
        fi
        sort -m -o "$1"

;-)


meillo

Reply via email to