zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: globbing in a for loop may prematurely exit script when sourcing a zsh script
Date: Wed, 31 Jul 2013 10:02:47 +0100	[thread overview]
Message-ID: <20130731100247.441731f2@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <480F89D7-0191-4D79-B4D8-98E10E80436F@salk.edu>

On Wed, 31 Jul 2013 01:13:47 -0700
Chris Hiestand <chiestand@salk.edu> wrote:
> I am new to zsh and this is what I'm trying to do within /etc/zsh/zshenv:
> 
> > if [[ -d "/custom/zsh.d" ]]; then
> >   for f in /custom/zsh.d/*.zsh; do
> >     source $f
> >   done 2> /dev/null
> > fi
> > 
> > #Do more stuff below...
> 
> What happens in zsh 4.3.17 is that if /custom/zsh.d/*.zsh expands to
> no files, zsh acts as if it hits err_return and "Do more stuff" does
> not get executed.

Historically, the shell has certainly been quite aggressive at treating
glob failures as hard errors.  There are various options you can set to
select how the shell treats glob failures.

The right thing to do here is tell the shell to expand the pattern to an
empty string if there are no matches.  You can do this without changing
any options by appending (N) to the pattern, i.e.

  for f in /custom/zsh.d/*.zsh(N); do

This behaves as if the NULL_GLOB option was set for that pattern.  In
zsh (but not necessarily other shells) a "for" loop over an empty
expansion does nothing.

pws


  reply	other threads:[~2013-07-31  9:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-31  8:13 Chris Hiestand
2013-07-31  9:02 ` Peter Stephenson [this message]
2013-07-31 19:42   ` Chris Hiestand

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=20130731100247.441731f2@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /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).