sed -i symlink behavior...

Milos Jakubicek xjakub at fi.muni.cz
Wed Sep 2 16:46:22 UTC 2009


Could be related to:

https://bugzilla.redhat.com/show_bug.cgi?id=470912

(at least that would explain the difference between RHEL5 and F10 -- I 
don't have any explanation for the diff between F10 and F11/12).

Anyway F10 is the right behavior from my point of view...

--
Regards,
Milos

Dne 2.9.2009 17:35, Warren Togami napsal(a):
> 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?
>
> Warren Togami
> wtogami at redhat.com
>




More information about the devel mailing list