From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9715 invoked by alias); 9 Apr 2015 16:30:40 -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: 20115 Received: (qmail 16773 invoked from network); 9 Apr 2015 16:30:37 -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, SPF_HELO_PASS autolearn=ham version=3.3.2 X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@zsh.org From: Thorsten Kampe Subject: Catch `setopt nounset` Date: Thu, 9 Apr 2015 18:30:08 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p5de5aada.dip0.t-ipconnect.de User-Agent: MicroPlanet-Gravity/3.0.4 Hi, I'd to catch the call of a parameter that does not exist with `setopt nounset`. ``` setopt nounset testfunc() { printf "$DOESNOTEXIST\n" } if testfunc then printf "no error\n" else printf "error\n" fi ``` This does not work. Neither the then nor else clause are entered. 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? ``` if result=$(testfunc) then printf "no error\n" else printf "error\n" fi ``` Thorsten