From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 490 invoked by alias); 9 Apr 2015 18:42:21 -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: 20116 Received: (qmail 25410 invoked from network); 9 Apr 2015 18:42:09 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=Zw8KpzbCD2nbF6p7GSF9xcQl+Ls64jy/pQ1YgT8hAN8=; b=jsuos25yGCLU2Z1gX37k7nGtLBiCwd+CiNjmSTzo10M1ypatgAw3GdXCwL6neG8KDP j1gEh1/BU2m7DZnKhwiIJNy3o7ihRd9YRs9mgXP5G/tEGXYBRwNW56l8NUKaEMEIRbDp omGHB7QFbTwdMY+VeL30X9oKahq2tLwDt9b0nDEcAqhN9zOVrM6KOtie38bd4QMJ9v4H AUBzS4aZPmm/X68dFpf4Td2ZUkus7XsmhVHjCQZ3W5FxLI0BTCCuVcslv1cX/TXrxwkU oXAtT4+FAd3xkZDIWqJj4l8Pu/bOznDtrE8W4e0Nw/WabTAW93ioEce8364Y+t3qoa37 19Kw== X-Gm-Message-State: ALoCoQksh/9yVzkLeW5Eo13VsIONQNDmx1gO68GS65m75R8HIXPSnP7czRyNKT9wJi5hb8Eaqhun X-Received: by 10.182.163.52 with SMTP id yf20mr40577158obb.69.1428604928091; Thu, 09 Apr 2015 11:42:08 -0700 (PDT) From: Bart Schaefer Message-Id: <150409114205.ZM25276@torch.brasslantern.com> Date: Thu, 9 Apr 2015 11:42:05 -0700 In-Reply-To: Comments: In reply to Thorsten Kampe "Catch `setopt nounset`" (Apr 9, 6:30pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Catch `setopt nounset` MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Apr 9, 6:30pm, Thorsten Kampe wrote: } } I'd to catch the call of a parameter that does not exist with `setopt } nounset`. setopt nounset { print "$DOESNOTEXIST" } always { if (( TRY_BLOCK_ERROR )) then print "error" else print "no error" fi } } If I replace the `catch` statement with `if result=$(testfunc)` it } prints "error". What am I missing here? Why does the latter work but } not the former? "parameter not set" is a fatal error, so whatever the current shell is doing is stopped when that happens. $(testfunc) is run in a subshell, so the current shell proceeds even though the subshell died. You could get the same result with if ( testfunc ) then printf "no error\n" else printf "error\n" fi but of course that also suppresses all other side-effects of "testfunc", which the "always" construct will not.