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

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

问题描述

我有这个函数,我需要它从使用 GNU 并行的函数中引用多个参数.

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 执行 bash*.sh* 里面的 folders_with_scripts 目录.

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 不会削减它.

*script.sh交换$1的位置不会剪掉它

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)

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

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