1

The solution for Bash is here: How to determine function name from inside a function

How can I do the same thing in Z shell, getting the function name from inside the function?

Update: there is a similar but distinct question asking about getting the name of the calling function. It is quite plain that the calling function and current function are distinct things. Although the answers are closely related, the questions are entirely distinct.

iconoclast
  • 21,213
  • 15
  • 102
  • 138
  • See [here](https://stackoverflow.com/questions/31426565/get-name-of-calling-function-in-zsh) for a comparision of bash and zsh in this respect. – user1934428 Feb 12 '20 at 07:44
  • Does this answer your question? [Get name of calling function in zsh](https://stackoverflow.com/questions/31426565/get-name-of-calling-function-in-zsh) – Tom Regner Feb 12 '20 at 11:30
  • That **question** is _a different question,_ but the answer does give an answer to this question. That asked for the zsh version of `${FUNCNAME[1]}` and I asked for the zsh version of `${FUNCNAME[0]}` – iconoclast Feb 13 '20 at 03:29

1 Answers1

1

The answer is given at https://stackoverflow.com/a/31426948/241142 (even though the question it is attached to asked for the calling function and not the current function, it gave the current function). I'll repeat it here:

The function call stack is in the variable $funcstack[].

$ your_function(){echo $funcstack[1];}
$ your_function
your_function
iconoclast
  • 21,213
  • 15
  • 102
  • 138