Determine if a function exists in bash

后端 未结 13 2500
再見小時候
再見小時候 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条回答
  • 2020-11-30 18:17

    From my comment on another answer (which I keep missing when I come back to this page)

    $ fn_exists() { test x$(type -t $1) = xfunction; }
    $ fn_exists func1 && echo yes || echo no
    no
    $ func1() { echo hi from func1; }
    $ func1
    hi from func1
    $ fn_exists func1 && echo yes || echo no
    yes
    
    0 讨论(0)
提交回复
热议问题