sed -i symlink behavior...

Warren Togami wtogami at redhat.com
Wed Sep 2 15:35:10 UTC 2009


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 fedora-devel-list mailing list