Search code examples
bashgroupingsubshell

Bash: command grouping with curly braces inside subshell


When I'm trying something like this:

( echo && { echo ; echo } )

I'm getting:

-bash: syntax error near unexpected token `)'

I'm sure that I need to use subshell. And I'm sure that I need grouping inside of it. So how do I avoid the syntax error? Thank you in advance!


Solution

  • A command list must be terminated with a ; or a newline.

    Instead say:

    ( echo && { echo ; echo ; } )
                           ^^^
                            |======= Add this
    

    From info bash:

       { list; }
              list  is simply executed in the current shell environment.  list
              must be terminated with a newline or semicolon.  This  is  known
              as  a  group  command. ...