Forward function declarations in a Bash or a Shell script?

后端 未结 2 1719
野趣味
野趣味 2020-12-04 09:32

Is there such a thing in bash or at least something similar (work-around) like forward declarations, well known in C / C++, for instance?

Or there is so

2条回答
  •  暖寄归人
    2020-12-04 10:14

    When my bash scripts grow too much, I use an include mechanism:

    File allMyFunctions:

    foo() {
    }
    
    bar() {
    }
    
    baz() {
    }
    

    File main:

    #!/bin/bash
    
    . allMyfunctions
    
    foo
    bar
    baz
    

提交回复
热议问题