zsh-users
 help / color / mirror / code / Atom feed
From: Chris Hiestand <chiestand@salk.edu>
To: zsh-users@zsh.org
Subject: globbing in a for loop may prematurely exit script when sourcing a zsh script
Date: Wed, 31 Jul 2013 01:13:47 -0700	[thread overview]
Message-ID: <480F89D7-0191-4D79-B4D8-98E10E80436F@salk.edu> (raw)


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.


Here is a test script test.zsh:

> #!/usr/bin/zsh
> setopt
> unsetopt histignorealldups
> unsetopt login
> unsetopt monitor
> unsetopt sharehistory
> unsetopt zle
> echo 'setopt again'
> setopt
> 
> 
> echo "Test 1"
> 
> ls /tmp/doesnotexist*
> 
> echo "Test 1 passed"
> 
> echo "Test 2"
> 
> if [ -d "/usr" ]; then
>   for f in /usr/*.zsh; do
>     echo $f
>   done
> fi
> 
> echo "Test 2 passed"



> user@host /tmp % ./test.zsh                                                                                                                             
> nohashdirs
> setopt again
> nohashdirs
> Test 1
> ./test.zsh:15: no matches found: /tmp/doesnotexist*
> Test 1 passed
> Test 2
> ./test.zsh:22: no matches found: /usr/*.zsh
> Test 2 passed
> 


> user@host /tmp % source test.zsh                                                                                                                       
> interactive
> setopt again
> interactive
> Test 1
> test.zsh:15: no matches found: /tmp/doesnotexist*
> Test 1 passed
> Test 2
> test.zsh:22: no matches found: /usr/*.zsh
> # Test 2 never finishes!


It seems that this problem is limited to interactive shells. Is this a bug or is this desirable behavior?

Thanks!

             reply	other threads:[~2013-07-31  8:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-31  8:13 Chris Hiestand [this message]
2013-07-31  9:02 ` Peter Stephenson
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=480F89D7-0191-4D79-B4D8-98E10E80436F@salk.edu \
    --to=chiestand@salk.edu \
    --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).