Bash:在子shell中使用花括号进行命令分组

时间:2014-05-19 18:39:54

标签: bash grouping subshell

当我尝试这样的事情时:

( echo && { echo ; echo } )

我得到了:

-bash: syntax error near unexpected token `)'

我确定我需要使用子shell。而且我确信我需要在其中进行分组。那么我该如何避免语法错误呢? 提前谢谢!

1 个答案:

答案 0 :(得分:3)

命令列表必须以;或换行符终止。

相反说:

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

来自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. ...