并行:如何从一个函数引用多个参数 [英] Parallel: How to reference multiple arguments from a function

查看:100
本文介绍了并行:如何从一个函数引用多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个函数,我需要它使用GNU parallel来引用一个函数中的多个参数.

I have this function and I need it to reference multiple arguments from a function using GNU parallel.

foo () {

    cd ${HOME}/sh/xxx/xxx/xxx/folder_with_scripts
    bash -H $1 #replace with echo in test run {echo $1 is being echoed}
    bash -H $2 #replace with echo in test run {echo $2 is being echoed}
}

export -f foo
parallel foo ::: *script.sh bash*.sh

folder_with_scripts内容

$ ls
firstscript.sh
secondscript.sh
thirdscript.sh
bashhim.sh
bashscript.sh
bashher.sh

parallel foo基本上将*script.sh之后的所有脚本引用为foo内部的参数来执行.这是$1.我想做的是让它也通过使用$2执行folders_with_scripts目录中的bash*.sh*.

parallel foo basically executes all scripts following *script.sh inside by referencing it as an argument inside foo. Which is $1. What I'm trying to do is have it also execute bash*.sh* which are inside folders_with_scriptsdirectory by using $2.

根据man parallel,语法为:

 parallel [options] [command [arguments]] ( ::: arguments | :::: argfile(s) )

由于::: arguments是复数形式,所以我认为这很有可能.

Since ::: arguments is plural, I'm assuming this is very possible.

$ ./foo.sh
firstscript.sh is being echoed
secondscript.sh is being echoed
thirdscript.sh is being echoed
              is being echoed
              is being echoed
              is being echoed

想要的结果

firstscript.sh is being echoed
secondscript.sh is being echoed
thirdscript.sh is being echoed
bashhim.sh is being echoed
bashscript.sh is being echoed
bashher.sh is being echoed

对于我来说,parallel foo ::: *.sh不会删掉它.

$1的位置替换为*script.sh不会将其剪切

For my case, parallel foo ::: *.sh won't cut it.

Swapping the positions of $1 with *script.sh won't cut it

推荐答案

您的问题不包含MVCE https://stackoverflow.com/help/mcve 特别是我无法直接在系统上运行您的代码.因此,此答案基于我对我认为您正在尝试做的事情的最佳猜测.

Your question does not contain an MVCE https://stackoverflow.com/help/mcve In particular I cannot run your code directly on my system. So this answer is based on my best guess of what I think you are trying to do.

假设您要为每个*script.sh运行所有bash*.sh:

Assuming you want to run all bash*.sh for each *script.sh:

parallel foo ::: *script.sh ::: bash*.sh

如果每个bash*.sh都链接到*script.sh(在版本20160422中引入了:::+):

If each bash*.sh is linked to a *script.sh (:::+ is introduced in version 20160422):

parallel foo ::: *script.sh :::+ bash*.sh

--dry-run进行测试:

parallel --dry-run foo ::: *script.sh ::: bash*.sh
parallel --dry-run foo ::: *script.sh :::+ bash*.sh

如果这不能回答您的问题,请使用您要运行GNU Parallel的命令来更新问题,例如:

If this does not answer your question, please update the question with what commands you want GNU Parallel to run, e.g.:

foo firstscript.sh bashhim.sh
foo secondscript.sh thirdscript.sh
foo bashscript.sh bashher.sh

并在运行parallel的目录中显示echo *script.sh bash*.sh的输出.

and show the output of echo *script.sh bash*.sh in the dir where you run parallel.

:::后面的数据称为输入源. https://zenodo.org/record/1146014 (打印: http://www. lulu.com/shop/ole-tange/gnu-parallel-2018/paperback/product-23558902.html )

The data behind ::: is called an input source. Dealing with input sources is covered in chapter 4 of https://zenodo.org/record/1146014 (Printed: http://www.lulu.com/shop/ole-tange/gnu-parallel-2018/paperback/product-23558902.html)

这篇关于并行:如何从一个函数引用多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆