Newsgroups: comp.unix.shell,comp.unix.solaris,comp.unix.programmer
Remove the symlink and then recreate it:
lchmod() { if [ ! -h "$1" ]; then echo "$1 is not a symlink." >&2 exit 1 fi symlink=`ls -ld $1 | awk '{print $9}'` target=`ls -ld $1 | awk '{print $11}'` rm $1 ln -s $target $symlink }
This won't work if either of the names contains whitespace.
You can do a little better by splitting on the ' -> ', but even that isn't reliable (consider "ln -s 'a -> b' c"). To make it robust you would have to resort to a C program or perl script (or anything else that can do a proper readlink() call).
Geoff Clare
documented on: 2001.03.21 Wed 16:37:52