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 content
$ ls
firstscript.sh
secondscript.sh
thirdscript.sh
bashhim.sh
bashscript.sh
bashher.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_scripts
directory by using $2
.
According to man parallel
, the syntax is:
parallel [options] [command [arguments]] ( ::: arguments | :::: argfile(s) )
Since ::: arguments
is plural, I'm assuming this is very possible.
result
For convenience sake, I'm replacing bash
with 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
wanted result
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
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.
Assuming you want to run all
bash*.sh
for each*script.sh
:If each
bash*.sh
is linked to a*script.sh
(:::+
is introduced in version 20160422):Test it with
--dry-run
:If this does not answer your question, please update the question with what commands you want GNU Parallel to run, e.g.:
and show the output of
echo *script.sh bash*.sh
in the dir where you runparallel
.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)