From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19804 invoked by alias); 24 Sep 2011 18:37:10 -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: 16420 Received: (qmail 4647 invoked from network); 24 Sep 2011 18:37:07 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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.216.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type:content-transfer-encoding; bh=nkNkB/gDfRGEow2QWYyGR2I6kagZJQ9pHmrIJLskm1k=; b=m3cAOD/5bPgmZRc/wI1JqIIgYpDpdbQp1FuFzhVvkjMtvq+HEWcPt/OQZXwGQHHo7x co1GDu7lwd8tvDfUmNGcw/iDGG7C6w8UwacWFNWeE7DSyMGbSo02XABozyHnD7+6HZd6 OM/kgDMvt5EMB92ZkAeHXUZHuF59shtnwC7AE= MIME-Version: 1.0 Sender: luomat@gmail.com From: TJ Luoma Date: Sat, 24 Sep 2011 14:09:49 -0400 X-Google-Sender-Auth: n3EvW_oukz7uGMk738fEE2G95wY Message-ID: Subject: a better way to 'die'? To: Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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? TjL