Date: Fri, 4 Mar 2011 20:05:45 +0100 From: Jilles Tjoelker <jilles@stack.nl> To: Stephen Montgomery-Smith <stephen@missouri.edu> Cc: FreeBSD Stable <freebsd-stable@freebsd.org> Subject: Re: Change in behavior to stat(1) Message-ID: <20110304190545.GA38881@stack.nl> In-Reply-To: <4D6BD83B.3040609@missouri.edu> References: <4D6BD83B.3040609@missouri.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Feb 28, 2011 at 11:15:39AM -0600, Stephen Montgomery-Smith wrote:
> I had a little script that would remove broken links. I used to do it
> like this:
> if ! stat -L $link > /dev/null; then rm $link; fi
> But recently (some time in February according to the CVS records) stat
> was changed so that stat -L would use lstat(2) if the link is broken.
> So I had to change it to
> if stat -L $link | awk '{print $3}' | grep l > /dev/null;
> then rm $link; fi
> but it is a lot less elegant.
> What is the proper accepted way to remove broken links?
A better answer to your original question was already given, but for
that command, isn't it sufficient to do
if ! [ -e $link ]; then rm $link; fi
All test(1)'s primaries that test things about files follow symlinks,
except for -h/-L.
--
Jilles Tjoelker
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110304190545.GA38881>
