From: TJ Luoma <tj@luo.ma>
To: Zsh Users <zsh-users@zsh.org>
Subject: a better way to 'die'?
Date: Sat, 24 Sep 2011 14:09:49 -0400 [thread overview]
Message-ID: <CADjGqHsFmUL=X6oWktW+X2eNQjQpPVyPCZ1htX8hSY-xRsBPsA@mail.gmail.com> (raw)
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
next reply other threads:[~2011-09-24 18:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-24 18:09 TJ Luoma [this message]
2011-09-24 18:47 ` Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADjGqHsFmUL=X6oWktW+X2eNQjQpPVyPCZ1htX8hSY-xRsBPsA@mail.gmail.com' \
--to=tj@luo.ma \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).