且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Shell脚本中使用并行执行?

更新时间:2023-11-11 22:17:58

将其转换为具有适当依赖性的Makefile.然后,您可以使用make -j让Make并行运行一切.

Convert this into a Makefile with proper dependencies. Then you can use make -j to have Make run everything possible in parallel.

请注意,Makefile中的所有缩进必须 是TAB. TAB显示生成"命令的运行位置.

Note that all the indents in a Makefile must be TABs. TAB shows Make where the commands to run are.

还请注意,此Makefile现在正在使用GNU Make扩展名(通配符和subst函数).

Also note that this Makefile is now using GNU Make extensions (the wildcard and subst functions).

它可能看起来像这样:

export PATH := .:${PATH}

FILES=$(wildcard file*)
RFILES=$(subst file,r,${FILES})

final: combine ${RFILES}
    combine ${RFILES} final
    rm ${RFILES}

ex: example.c

combine: combine.c

r%: file% ex
    ex $< $@