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

globbing in a for loop may prematurely exit script when sourcing a zsh script



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!


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