我有这个函数,我需要它引用一个使用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
包含脚本内容的文件夹
$ ls
firstscript.sh
secondscript.sh
thirdscript.sh
bashhim.sh
bashscript.sh
bashher.sh
parallel foo
基本上通过将其作为*script.sh
内的参数引用来执行foo
内的所有脚本。即$1
。我要做的是让它也通过使用bash*.sh*
来执行folders_with_scripts
目录中的$2
。根据
man parallel
,语法为: parallel [options] [command [arguments]] ( ::: arguments | :::: argfile(s) )
因为
::: arguments
是复数,所以我假设这是非常可能的。结果
为了方便起见,我将
bash
替换为echo
$ ./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
的位置交换不会切断它 最佳答案
你的问题不包含MVCEhttps://stackoverflow.com/help/mcve特别是我不能直接在我的系统上运行你的代码。所以这个答案是基于我对你的猜测。
假设要为每个bash*.sh
运行所有*script.sh
:
parallel foo ::: *script.sh ::: bash*.sh
如果每个
bash*.sh
链接到*script.sh
(:::+
在版本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并行运行的命令更新问题,例如:
foo firstscript.sh bashhim.sh
foo secondscript.sh thirdscript.sh
foo bashscript.sh bashher.sh
并在运行
echo *script.sh bash*.sh
的目录中显示parallel
的输出。:::
后面的数据称为输入源。有关输入源的处理,请参见https://zenodo.org/record/1146014的第4章(印刷体:http://www.lulu.com/shop/ole-tange/gnu-parallel-2018/paperback/product-23558902.html)
关于bash - 并行:如何从一个函数引用多个参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50636075/