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

Re: sed -i symlink behavior...



On Wed, Sep 2, 2009 at 5:35 PM, Warren Togami <wtogami redhat com> wrote:
I just noticed some behavior changes within sed.  Run the following commands in various distros.

#!/bin/bash
set -x
echo "abc" > original.txt
ln -s original.txt symlink.txt
sed -i 's/abc/123/' symlink.txt
if [ -L symlink.txt ]; then
   echo yes symlink
else
   echo not symlink anymore
fi
cat original.txt
cat symlink.txt

RHEL5
=====
[user rhel5 ~]$ echo "abc" > original.txt
[user rhel5 ~]$ ln -s original.txt symlink.txt
[user rhel5 ~]$ sed -i 's/abc/123/' symlink.txt
sed: ck_follow_symlink: couldn't lstat s/original.txt: No such file or directory
[user rhel5 ~]$ cat symlink.txt
abc
[user rhel5 ~]$ cat original.txt
abc

original.txt is unmodified, symlink.txt is still a symlink.

Fedora 10
=========
[user fedora10 ~]$ echo "abc" > original.txt
[user fedora10 ~]$ ln -s original.txt symlink.txt
[user fedora10 ~]$ sed -i 's/abc/123/' symlink.txt
[user fedora10 ~]$ cat symlink.txt
123
[user fedora10 ~]$ cat original.txt
123

original.txt is modified, symlink.txt is still a symlink.

Fedora 11 and 12
================
[user fedora11 ~]$ echo "abc" > original.txt
[user newcaprica ~]$ ln -s original.txt symlink.txt
[user newcaprica ~]$ sed -i 's/abc/123/' symlink.txt
[user newcaprica ~]$ cat original.txt
abc
[user newcaprica ~]$ cat symlink.txt
123

original.txt is not modified, symlink.txt is no longer a symlink. symlink.txt now contains a modified version of original.txt as a plain file.

What is the correct behavior?  Is this a bug that it changed?


Also

perl -pi -e 's/abc/123/g' symlink.txt

always have got the same result.
 
Warren Togami
wtogami redhat com

--
fedora-devel-list mailing list
fedora-devel-list redhat com
https://www.redhat.com/mailman/listinfo/fedora-devel-list


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