How to use double or single brackets, parentheses, curly braces

后端 未结 7 914
心在旅途
心在旅途 2020-11-21 23:10

I am confused by the usage of brackets, parentheses, curly braces in Bash, as well as the difference between their double or single forms. Is there a clear explanation?

7条回答
  •  余生分开走
    2020-11-21 23:42

    Parentheses in function definition

    Parentheses () are being used in function definition:

    function_name () { command1 ; command2 ; }
    

    That is the reason you have to escape parentheses even in command parameters:

    $ echo (
    bash: syntax error near unexpected token `newline'
    
    $ echo \(
    (
    
    $ echo () { command echo The command echo was redefined. ; }
    $ echo anything
    The command echo was redefined.
    

提交回复
热议问题