Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

a better way to 'die'?



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