$FUNCNAME  –  Function Call Stack

$FUNCNAME contains the names of shell functions on the execution call stack.

The name of the currently executed function is ${FUNCNAME[0]}, the name of the calling function is ${FUNCNAME[1]} and so on.

The element with the highest index has value main. This value is representing the entry-point of a shell script file. It’s unavailable if a function is executed inside an interactive shell, for example.

Examples

Print the function call stack with $FUNCNAME
1
2
3
function nested() { echo "Function call stack:" "${FUNCNAME[@]}"; }
function topLevel() { nested; }
topLevel
Output:
1
Function call stack: nested topLevel main
BashSupport Pro is a Bash IDE with support for $FUNCNAMEtry it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal