If I have a Bash script like:
#!/bin/bash
f() {
# echo function name, \"f\" in this case
}
Is there any way to do this? This could be us
The simplest way to get the function name (from inside a function) is dependent on which shell you are using:
someFunctionName() {
echo $funcstack[1]
}
someFunctionName() {
echo ${FUNCNAME[0]}
}
someFunctionName() {
currentShell=$(ps -p $$ | awk "NR==2" | awk '{ print $4 }' | tr -d '-')
if [[ $currentShell == 'bash' ]]; then
echo ${FUNCNAME[0]}
elif [[ $currentShell == 'zsh' ]]; then
echo $funcstack[1]
fi
}