In Bash I want to be able to write something like:
tst() {
[ -z "$1" ] && die "No parameters provided!"
# do whatever
}
but I cannot define die
like this:
die() {
echo "$*"
exit 1
}
because if my test function is running in my current shell (e.g. . ./file-with-function
) then it aborts my current session. what I really want it to do is something more along the lines of:
tst() {
[ -z "$1" ] && echo "No parameters provided!" && return
}
but I want to do the echo and return in a single function call. is there a clever way to do this?