shell bash脚本里,如何检测函数是否已经定义了?

2026年09月26日 05:58
有2个网友回答
网友(1):

通过函数名:

if [ "$(type -t func)" = "function" ] ; then
    echo "func is exists"
fi


通过字符串变量:

funcname="func"
if [ "$(type -t $funcname)" = "function" ] ; then
    echo "$funcname is exists"
fi

网友(2):

检测函数是否已经定义的话 可以echo你的变量先试一下