What are the parentheses used for in a bash shell script function definition like “f () {}”? Is it different than using the “function” keyword?

后端 未结 3 942
灰色年华
灰色年华 2020-12-28 12:21

I\'v always wondered what they\'re used for? Seems silly to put them in every time if you can never put anything inside them.

function_name () {
    #stateme         


        
3条回答
  •  眼角桃花
    2020-12-28 13:10

    Without function, alias expansion happens at definition time. E.g.:

    alias a=b
    # Gets expanded to "b() { echo c; }" :
    a() { echo c; }
    b
    # => c
    # Gets expanded to b:
    a
    # => c
    

    With function however, alias expansion does not happen at definition time, so the alias "hides" the definition:

    alias a=b
    function a { echo c; }
    b
    # => command not found
    # Gets expanded to b:
    a
    # => command not found
    unalias a
    a
    # => c
    

提交回复
热议问题