GNU 并行:如何取消引号`;`以便可以运行多个命令?

问题描述 投票:0回答:1

如何使用

--quote
/
-q
选项运行多个命令?

例如,这引用了

;
:

$ parallel --dry-run -q command1 {1} \; command2 ::: "With a space" "Another space" "Yet more spaces" "WithoutASpace" 
command1 'With a space' ';' command2
command1 'Another space' ';' command2
command1 'Yet more spaces' ';' command2

¿如何取消引用它以便它运行:

command1 'With a space' ; command2
command1 'Another space' ; command2
command1 'Yet more spaces' ; command2

我知道我的MWE可能不需要

-q
,但是当我有更复杂的命令和需要引号的参数时,我遇到了单引号并行放置“泄漏”到传递给的文本中的问题命令。

quotes gnu-parallel single-quotes unquoting
1个回答
0
投票

您已经给出了解决方案:删除-q,并解决了这个问题:

当我有更复杂的命令时

https://www.gnu.org/software/parallel/man.html#quoting 说:

结论:如果这令人困惑,请考虑避免通过编写小脚本或函数(记住导出 -f 函数)来处理引用,并让 GNU 并行调用它。

您仍然可以使用 GNU Parallel 来生成参数。

所以:

doit() {
  echo "$1" "$2" "$3"
  # You can put comments in the code
  echo do complex stuff here
}
export -f doit
parallel doit {1/} {1.} {2} ::: */* ::: jpg png webp

恕我直言,它通常也可以提高可读性。

© www.soinside.com 2019 - 2024. All rights reserved.