有没有办法使用它的输入在 GNU 中并行计算?

Is there a way to do calculations in GNU parallel using its inputs?

我在 linux 上使用 GNU parallel,我想在其中做一些计算,但我无法用它来替代输入。

从这里开始,效果很好:

parallel echo {1} {2} ::: {1..2} ::: {1..2}

输出:

1 1
1 2
2 1
2 2

我想做这样的事情:

parallel echo {1} $(({2} *2)) ::: {1..2} ::: {1..2}

但我得到的只是:

bash: {2} * 2: syntax error: operand expected (error token is "{2} * 2")

我尝试使用 expr,但问题是一样的,第二个参数没有被替换:

parallel echo {1} $(expr {2} \* 2 ) ::: {1..2} ::: {1..2}
expr: non-integer argument
1
1
2
2

有没有办法让它起作用?

parallel echo {1} '{=1 $_=$arg[2]*2 =}' ::: {1..2} ::: {1..2}

您不仅限于使用单个参数进行计算:

parallel echo {1} '{=1 $_=$arg[1]/$arg[2] =}' ::: {1..2} ::: {1..2}

如果您喜欢在 shell 中使用它,您只需引用它:

parallel echo {1} '$(expr {2} \* 2 )' ::: {1..2} ::: {1..2}