bash: start multiple chained commands in background

前端 未结 15 921
生来不讨喜
生来不讨喜 2020-12-07 22:47

I\'m trying to run some commands in paralel, in background, using bash. Here\'s what I\'m trying to do:

forloop {
  //this part is actually written in perl
          


        
15条回答
  •  感情败类
    2020-12-07 23:23

    The facility in bash that you're looking for is called Compound Commands. See the man page for more info:

    Compound Commands A compound command is one of the following:

       (list) list  is  executed  in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).  Variable assignments and
              builtin commands that affect the shell's environment do not remain in effect after  the  command  completes.   The
              return status is the exit status of list.
    
       { 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.  The return status is the exit status of list.  Note that unlike the metacharac‐
              ters  (  and  ),  {  and  } are reserved words and must occur where a reserved word is permitted to be recognized.
              Since they do not cause a word break, they must be separated from list by whitespace or another shell  metacharac‐
              ter.
    

    There are others, but these are probably the 2 most common types. The first, the parens, will run a list of command in series in a subshell, while the second, the curly braces, will a list of commands in series in the current shell.

    parens

    % ( date; sleep 5; date; )
    Sat Jan 26 06:52:46 EST 2013
    Sat Jan 26 06:52:51 EST 2013
    

    curly braces

    % { date; sleep 5; date; }
    Sat Jan 26 06:52:13 EST 2013
    Sat Jan 26 06:52:18 EST 2013
    

提交回复
热议问题