From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21606 invoked by alias); 24 Sep 2011 18:47:20 -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: 16421 Received: (qmail 22477 invoked from network); 24 Sep 2011 18:47:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.212.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=TdgIZ6qQrsS0o77i+P4HtmRIv8uRyUU9RUGaGUkRcNI=; b=JMmQbdquXkzo6eRxzfuqT6dqfC9CVLuS+zqT9Mv0rmBETMjLffN+Z7on6BO7MfCsTI u9BdZEs09d7SpoNVIGFW20ZCOoukapi1/nxUTEaQiY0WrYspU9hLFbL1ROpsnupg2KPx iiyBps4kR1dg1oMisiJz1xV+Rfwhg/8Tn2vvA= MIME-Version: 1.0 In-Reply-To: References: Date: Sat, 24 Sep 2011 20:47:02 +0200 Message-ID: Subject: Re: a better way to 'die'? From: Mikael Magnusson To: TJ Luoma Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 24 September 2011 20:09, TJ Luoma wrote: > I have a function 'die' in my .zshenv that looks like this: > > die () { > > echo "$@" > > if [ "$SHLVL" =3D "1" ] > then > return 1 > else > exit 1 > fi > } > > The purpose is so I can do things like: > > [[ -e "/path/to/file.txt" ]] || die "Did not find /path/to/file.txt!" > > to easily quit a loop (using return 1) or a script (using exit 1) > after echoing a message explaining where things broke down. (That > seems better than just throwing an 'exit 1' or 'return 1' and leaving > the user =E2=80=94 usually me =E2=80=94 to figure out where things failed= .) > > Is there a better way to do this? If you have a recent enough zsh, look at $zsh_eval_context[-1] --=20 Mikael Magnusson