Work-around for $@ unbound variable in Bash 4.0.0? Work-around for $@ unbound variable in Bash 4.0.0? shell shell

Work-around for $@ unbound variable in Bash 4.0.0?


$@, $* are special variables so should always be defined it's a bug

https://unix.stackexchange.com/questions/16560/bash-su-unbound-variable-with-set-u

a workaround, maybe:

set +uargs=("$@")set -umain "${args[@]}"

or maybe also

main "${@:+$@}"


Why not do error handling on your own? This way you can control exactly what happens when an exception is encountered, for instance return a custom exit code and message for that error, rather than be confined to some predefined behavior.

function log_error                                                          {                                                                               [[ $# -ne 1 ]] && return 1                                                  typeset msg="$1"                                                            typeset timestamp=$(date "+%F %T")                                          echo "[${timestamp}] [ERROR] - $msg " >&2                               }if [[ -z "$BASH_VERSION" ]]                                                 then                                                                            log_error "BASH VERSION is not set"                                         exit 1                                                                  fi