Bash can print the current function name:
$ bash -c 'g(){ echo $FUNCNAME; }; g'
g
However Dash cannot use FUNCNAME:
$ dash -c 'g(){ echo $FUNCNAME; }; g'
It is possible to access the current function name with Dash?
Bash can print the current function name:
$ bash -c 'g(){ echo $FUNCNAME; }; g'
g
However Dash cannot use FUNCNAME:
$ dash -c 'g(){ echo $FUNCNAME; }; g'
It is possible to access the current function name with Dash?
With any POSIX shells:
defun() {
eval "
$1() {
FUNCNAME=$1
$(cat)
}
"
}
defun g <<\}
printf '%s\n' "$FUNCNAME"
}
g
Note that you can't call a function defined by defun inside body of a function defined by defun.
FUNCNAME variable, e.g. using / as a separator (I don't think any shell allows slashes in function names). It would be tricky to catch all return statements though, but you could make wrapper functions instead.