Determine if a function exists in bash

后端 未结 13 2610
再見小時候
再見小時候 2020-11-30 17:39

Currently I\'m doing some unit tests which are executed from bash. Unit tests are initialized, executed and cleaned up in a bash script. This script usualy contains an init(

13条回答
  •  -上瘾入骨i
    2020-11-30 17:53

    It is possible to use 'type' without any external commands, but you have to call it twice, so it still ends up about twice as slow as the 'declare' version:

    test_function () {
            ! type -f $1 >/dev/null 2>&1 && type -t $1 >/dev/null 2>&1
    }
    

    Plus this doesn't work in POSIX sh, so it's totally worthless except as trivia!

提交回复
热议问题