bug-sed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31261: -i replaces symlinks with new file


From: Assaf Gordon
Subject: bug#31261: -i replaces symlinks with new file
Date: Wed, 25 Apr 2018 16:19:51 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

tag 31261 notabug
close 31261
thanks

Hello Daniel,

On 25/04/18 01:38 PM, Daniel Bosk wrote:
Not sure if it's intended behaviour or not, but I didn't expect it and I
found no note in the man-page either. Consider the following:

   echo "test" > testfile
   ln -s testfile testlink
   cat testfile testlink
   sed -i "s/test/fail/" testlink
   cat testfile testlink

The first cat will output "test\ntest". I would expect the second to
output "fail\nfail" but it outputs "test\nfail". The reason is that sed
has replaced the symlink with a new file instead of modifying the file
the symlink points to.

This is the intended behavior, and exactly to address your
issue GNU sed has a "--follow-symlinks" option:

  --follow-symlinks
                 follow symlinks when processing in place

Observe the following:

  $ echo test > a
  $ ln -s a b
  $ ln -s a c
  $ ls -lhog
  total 4.0K
  -rw-r--r-- 1 5 Apr 25 16:15 a
  lrwxrwxrwx 1 1 Apr 25 16:16 b -> a
  lrwxrwxrwx 1 1 Apr 25 16:16 c -> a

  $ sed -i 's/test/fail/' b
  $ sed --follow-symlinks -i 's/test/fail/' c

  $ ls -lhog
  total 8.0K
  -rw-r--r-- 1 5 Apr 25 16:16 a
  -rw-r--r-- 1 5 Apr 25 16:16 b
  lrwxrwxrwx 1 1 Apr 25 16:16 c -> a

  $ head *
  ==> a <==
  fail

  ==> b <==
  fail

  ==> c <==
  fail


As such I'm closing the bug report, but discussion can continue by replying to this thread.

regards,
 - assaf





reply via email to

[Prev in Thread] Current Thread [Next in Thread]