sed -i symlink behavior...

yersinia yersinia.spiros at gmail.com
Wed Sep 2 16:31:18 UTC 2009


On Wed, Sep 2, 2009 at 5:35 PM, Warren Togami <wtogami at 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 at rhel5 ~]$ echo "abc" > original.txt
> [user at rhel5 ~]$ ln -s original.txt symlink.txt
> [user at rhel5 ~]$ sed -i 's/abc/123/' symlink.txt
> sed: ck_follow_symlink: couldn't lstat s/original.txt: No such file or
> directory
> [user at rhel5 ~]$ cat symlink.txt
> abc
> [user at rhel5 ~]$ cat original.txt
> abc
>
> original.txt is unmodified, symlink.txt is still a symlink.
>
> Fedora 10
> =========
> [user at fedora10 ~]$ echo "abc" > original.txt
> [user at fedora10 ~]$ ln -s original.txt symlink.txt
> [user at fedora10 ~]$ sed -i 's/abc/123/' symlink.txt
> [user at fedora10 ~]$ cat symlink.txt
> 123
> [user at fedora10 ~]$ cat original.txt
> 123
>
> original.txt is modified, symlink.txt is still a symlink.
>
> Fedora 11 and 12
> ================
> [user at fedora11 ~]$ echo "abc" > original.txt
> [user at newcaprica ~]$ ln -s original.txt symlink.txt
> [user at newcaprica ~]$ sed -i 's/abc/123/' symlink.txt
> [user at newcaprica ~]$ cat original.txt
> abc
> [user at 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 at redhat.com
>
> --
> fedora-devel-list mailing list
> fedora-devel-list at redhat.com
> https://www.redhat.com/mailman/listinfo/fedora-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.fedoraproject.org/pipermail/devel/attachments/20090902/783011e4/attachment.html 


More information about the devel mailing list