POSIX compliant way to see if a function is defined in an sh script

后端 未结 2 1837
盖世英雄少女心
盖世英雄少女心 2021-01-07 04:02

I\'m after THE proper way to see if a function is defined or not. A POSIX compliant way.

__function_defined() {
    FUNC_NAME=$1
    d=$(declare -f $FUNCNAME         


        
2条回答
  •  -上瘾入骨i
    2021-01-07 04:24

    I have found a POSIX compliant way

    if [ "$(command -v $FUNC_NAME)x" != "x" ]; then
        echo " * INFO: Found function $FUNC_NAME"
        return 0
    fi
    

    The question now, Is there a better solution?

提交回复
热议问题