并行调用多个 bash 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34397426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
parallel call multiple bash functions
提问by p4guru
I have read the example at http://www.gnu.org/software/parallel/man.html#example__calling_bash_functionshowever, is it possible to use gnu parallel to call 2 functions which do not have any variables you pass to them ?
我已经阅读了http://www.gnu.org/software/parallel/man.html#example__calling_bash_functions 上的示例,但是,是否可以使用 gnu parallel 来调用 2 个没有传递给它们的变量的函数?
example
例子
a() {
echo "download a"
wget fileA
}
b() {
echo "download b"
wget fileB
}
and use parallel to call both functions a
& b
?
并使用 parallel 调用两个函数a
& b
?
回答by Thirupathi Thangavel
Run them in background. And then wait for them to complete.
在后台运行它们。然后等待它们完成。
a() {
echo "download a"
wget fileA
}
b() {
echo "download b"
wget fileB
}
a &
b &
wait # waits for all background processes to complete
回答by Ole Tange
If you insist on using GNU Parallel:
如果您坚持使用 GNU Parallel:
a() {
echo "download a"
wget fileA
}
b() {
echo "download b"
wget fileB
}
export -f a
export -f b
parallel ::: a b