Created
May 14, 2022 04:12
-
-
Save gh640/52abf6730c9a4136232ea7ef00a73a86 to your computer and use it in GitHub Desktop.
Zsh / Bash: Getting the current function name invoked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function func_name { | |
case "${SHELL}" in | |
*/bash) | |
# Bash | |
echo ${FUNCNAME[2]} | |
;; | |
*/zsh) | |
# Zsh | |
echo ${funcstack[2]} | |
;; | |
*) | |
echo "Unsupported shell: ${SHELL}." | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function works only inside another function.
Examples: