How to define a function inside another function in Bash?

前端 未结 6 1247
死守一世寂寞
死守一世寂寞 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 17:16

    Don't nest function definitions. replace with:

    $ cat try.bash 
    function one {
      echo "One"
    }
    
    function two {
      echo "Two"
    }
    
    function three {
       one
       two
    }
    
    three
    $ bash try.bash 
    One
    Two
    $ 
    

提交回复
热议问题