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

Re: Testing for broken symlinks



"Eric Mangold" wrote:
> Is there any way to test if a symlink is broken?

This will work:

  broken=(mylinktest(N-@))

  if (( ${#broken} )); then
    print mylinktest is a broken symbolic link
  else
    print mylinktest is not a symbolic link or is not broken
  fi

The basic point is that the command line argument mylinktest(N-@) is
removed unless mylinktest is a broken symbolic link, so you may have a
more efficient way to use the fact.

This works because - makes the shell follow symbolic links, while @
tells it to look only for symbolic links.  The only files that are
still resolved as symbolic links are those that are broken.  The N flag
then removes any failed glob, i.e. those not broken symbolic links.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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