Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
a better way to 'die'?
- X-seq: zsh-users 16420
- From: TJ Luoma <tj@xxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: a better way to 'die'?
- Date: Sat, 24 Sep 2011 14:09:49 -0400
- 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=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Sender: luomat@xxxxxxxxx
I have a function 'die' in my .zshenv that looks like this:
die () {
	echo "$@"
	if [ "$SHLVL" = "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 — usually me — to figure out where things failed.)
Is there a better way to do this?
TjL
Messages sorted by:
Reverse Date,
Date,
Thread,
Author