From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16422 invoked by alias); 31 Jul 2013 09:13:19 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17902 Received: (qmail 1532 invoked from network); 31 Jul 2013 09:13:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f5-b7f376d000001ec6-66-51f8d2b82e6e Date: Wed, 31 Jul 2013 10:02:47 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: globbing in a for loop may prematurely exit script when sourcing a zsh script Message-id: <20130731100247.441731f2@pwslap01u.europe.root.pri> In-reply-to: <480F89D7-0191-4D79-B4D8-98E10E80436F@salk.edu> References: <480F89D7-0191-4D79-B4D8-98E10E80436F@salk.edu> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmluLIzCtJLcpLzFFi42I5/e/4Vd0dl34EGpxcJ2Cx4+RKRgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZVx+ZFZwlqPiwMnnzA2MV9i6GDk5JARMJBY+mAJli0lcuLce yObiEBJYyijR/PEPK5TDJHHz6zV2kCoWAVWJu6c7WEBsNgFDiambZjOC2CICohLLV2wGquHg EBaIkViyxAgkzCtgL7H0bA9YCaeAjcTh5ztZQWwhAWuJ49OmgS3mF9CXuPr3ExPEEfYSM6+c YYToFZT4Mfke2CpmAS2JzduaWCFseYnNa94yT2AUmIWkbBaSsllIyhYwMq9iFE0tTS4oTkrP NdIrTswtLs1L10vOz93ECAnArzsYlx6zOsQowMGoxMPreOF7oBBrYllxZe4hRgkOZiURXvmg H4FCvCmJlVWpRfnxRaU5qcWHGJk4OKUaGIsTp5lolr//fkpno/7l5TfKfj29elf+dPem5Pii tP5dnz2edQgL9Os4vPv47Ot1xX33tjakTFljvzx+6q8XbHO7rF2/aoY570lZ8c9790sWCV+n O9MaCn9mHgutbHzvulrxoY1XOq9m7YLjPqF7DX68eXhml7/GnukbJs2fnexzVmPx9iU7tysr sRRnJBpqMRcVJwIAUOe/0h4CAAA= On Wed, 31 Jul 2013 01:13:47 -0700 Chris Hiestand 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