3 ms·
That's a nice list; I guess every experienced user has their helper functions. However, I have a small criticism for the philosophy of that `die`: `die` functi
by ykonstant 3y ago
That's a nice list; I guess every experienced user has their helper functions. However, I have a small criticism for the philosophy of that `die`: `die` functions should pass by default the exit code of the failed command, and not silence its error output. If I want to give my own meaning to the command failure in a large script for instance, I will use a different, more specialized `die`. My own die is roughly as follows:
__errex() {
printf 'Fatal error [%s] on line %s in '"'"'%s'"'"': %s\n' \
"${1:-"?"}" \
"${2:-"?"}" \
"${3:-"unknown script"}" \
"${4:-"unknown error"}" >&2 ;
exit "${1:-1}"
}
alias die='__errex "$?" "${LINENO}" "$0"'