如何知道 POSIX shell 脚本中 运行 的函数名称

How to know the function name that is running on a POSIX shell script

我想弄清楚是否有标准方法(不是有效的 hack)来了解当前在 POSIX shell 脚本上执行的函数的名称。我知道我可以用 [=13=] return 脚本的名称。如何应用类似于函数的东西?

快速搜索the latest POSIX standard表明没有,但是:

  • 行号 $LINENO 一个 POSIX 特征。
  • You can't get the script name reliably(甚至不是来自 [=11=]),因为它不是只读的,也不是由某些 shell 设置的。
  • 您可以使用 set -o xtrace 跟踪脚本。