【问题标题】:Bash- Run multiple commands at the same time [duplicate]Bash-同时运行多个命令[重复]
【发布时间】:2015-06-09 14:53:16
【问题描述】:

有没有办法同时运行多个命令,但直到两个都完成后才继续?我一直在尝试使用与以下类似的指令,但两者都需要很长时间才能完成,如果我可以同时运行它们会更好(不能使用 & 在后台运行它,因为下一步需要所有输出文件)

sed -i 's/x/y/' file1
grep 'pattern' file2 > file3 

【问题讨论】:

  • ( command )。这会启动一个子shell。它是多处理的。然后你可以在两个pid上调用wait。查看完整的文档:tldp.org/LDP/abs/html/index.html.
  • 你可以使用&等待

标签: linux bash


【解决方案1】:

这可能就是你想要的:

sed -i 's/x/y/' file1 &
grep 'pattern' file2 > file3 &
wait

【讨论】:

    【解决方案2】:

    不完全是答案,但几行 makefile 就可以满足您的需求

    file1:
        sed -i 's/x/y' <someinput
    
    file3: file2
        grep 'pattern' file2 > file3
    
    nextop: file1 file3
        whatever you want to do next
    

    并 make -j 以便在可能的情况下并行完成任务

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 2012-10-16
      • 1970-01-01
      相关资源
      最近更新 更多