How do I run multiple background commands in bash in a single line?

前端 未结 8 1818
栀梦
栀梦 2020-11-28 19:11

I normally run multiple commands with something like this:

sleep 2 && sleep 3

or

sleep 2 ; sleep 3
<
8条回答
  •  一生所求
    2020-11-28 19:45

    The answers above use parentheses. Bash also can use braces for a similar purpose:

    { sleep 2 && sleep 3; } &
    

    Note that the braces are more picky about syntax--the space after {, the space before }, and the final semicolon are required. In some situations the braces are more efficient because they don't fork a new subshell. In this case I don't know if it makes a difference.

提交回复
热议问题