GNU bug report logs - #49287
sed -i disrespects read-only

Previous Next

Package: sed;

Reported by: Leonid Mironov <lvm <at> royal.net>

Date: Wed, 30 Jun 2021 08:31:01 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Davide Brini <dave_br <at> gmx.com>
To: 49287 <at> debbugs.gnu.org
Subject: bug#49287: sed -i disrespects read-only
Date: Thu, 1 Jul 2021 15:22:07 +0200
On Wed, 30 Jun 2021 08:01:13 +0200, Leonid Mironov <lvm <at> royal.net> wrote:

>    Hello,
>
>    sed disrespects read-only file attributes when editing in place.
>
>    $ ls -l testfile*
>    -r--r--r-- 1 lvm lvm 50 Jun 30 08:32 testfile
>    $ sed 's/test/bug/g' -i~ testfile
>    $ diff testfile testfile~
>    2c2
>    < this is a bug
>    ---
>    > this is a test
>    $ sed --version
>    sed (GNU sed) 4.4

Well tecnically this is correct since sed never writes to the
original file, instead it creates a new file, writes to it and finally
renames it to the old name, so the original file permissions never come
into play (in case you're wondering: it's not really "in-place").

I agree it could be surprising, but once you know how it works behind
the scenes it should make a bit more sense.

--
D.




This bug report was last modified 4 years and 15 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.