zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: "zsh-users@sunsite.dk" <zsh-users@sunsite.dk>
Subject: Re: Testing for broken symlinks
Date: Wed, 20 Apr 2005 10:15:37 +0100	[thread overview]
Message-ID: <200504200915.j3K9Fbsi018162@news01.csr.com> (raw)
In-Reply-To: <opspishpc86k1y1x@aspen>

"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@csr.com>                  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.

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


  reply	other threads:[~2005-04-20  9:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-20  7:30 Eric Mangold
2005-04-20  9:15 ` Peter Stephenson [this message]
2005-04-20 17:20   ` Paul Lew
2005-04-21  7:02     ` Bart Schaefer
2005-04-20 10:51 ` Alexey Tourbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200504200915.j3K9Fbsi018162@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).