【问题标题】:How to display the function name into the function itself如何将函数名称显示到函数本身
【发布时间】:2013-07-17 11:24:21
【问题描述】:

如何在函数中显示函数名?

#!/bin/sh
toto()
{
    echo "$something"
}

toto

上面的代码应该会显示

toto

我正在使用来自busybox的bash linux

【问题讨论】:

    标签: linux bash shell busybox


    【解决方案1】:

    您可以使用$FUNCNAME 这样做。

    $ toto()
    > {
    > echo "this function name is $FUNCNAME"
    > }
    $ toto
    this function name is toto
    

    【讨论】:

    • 这适用于我的 ubuntu shell,但不适用于 BusyBox bash
    • 呃,那恐怕是不可能的。见mail-archive.com/slitaz@lists.tuxfamily.org/msg01550.html
    • 我相信 BusyBox 使用的是ash,而不是bashFUNCNAME 是在 2.0 版中添加到 bash 中的,因此不太可能是版本问题。
    猜你喜欢
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 2016-03-18
    相关资源
    最近更新 更多