bash die function

function die
{
    local message=$1
    [ -z "$message" ] && message="Died"
    echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: ${FUNCNAME[1]}: $message." >&2
    exit 1
}

So, Bash is keeping all needed info in several environment variables:
  • LINENO - current executed line number
  • FUNCNAME - call stack of functions, first element (index 0) is current function, second (index 1) is function that called current function
  • BASH_LINENO - call stack of line numbers, where corresponding FUNCNAME was called
  • BASH_SOURCE - array of source file, where corresponfing FUNCNAME is stored

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all