Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Testing for broken symlinks



On Wed, Apr 20, 2005 at 05:30:51PM +1000, Eric Mangold wrote:
> Is there any way to test if a symlink is broken?

if [ -L "$f" -a ! -e "$f" ]; then
	print "$f: broken symlink"
fi

$ ln -sf /asdf/zxcv .
$ test -L zxcv; echo $?
0
$ test -e zxcv; echo $?
1
$

The point is that lstat(2) succeeds but stat(2) fails on broken
symlinks.

Attachment: pgpIdqypo0Dec.pgp
Description: PGP signature



Messages sorted by: Reverse Date, Date, Thread, Author