How to define a function inside another function in Bash?

前端 未结 6 1235
死守一世寂寞
死守一世寂寞 2020-12-07 16:24

I have the following code

func1(){
    #some function thing
    function2(){
        #second function thing
    }
}

and I want to call

6条回答
  •  失恋的感觉
    2020-12-07 16:57

    If you're nesting a function, say function2 inside function1, it doesn't become available until function1 is called. Some people might consider this a feature, as you can do something like "unset function2" at the end of function1 and its scope is completely local to that function (can't be called from elsewhere). If you want to call the function elsewhere, there's probably no need to nest it anyway.

提交回复
热议问题