我需要将包含空白及其他字符的文本传递给由GNU Parallel运行的脚本。
下面是一个非常简单的示例:
$ seq 1 3 | parallel echo "Quoted ' (text)"
上面的示例将输出如下内容:
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
然而,如果我这样做一切都可以正常工作:
seq 1 3 | parallel echo "\"Quoted ' (text)\""
我碰巧是从Python脚本中运行的,因此在传递参数之前,我会像这样在脚本中对它们进行双引号括起来:
args = ["Some arg", "Another arg", "etc."]
args = ' '.join(pipes.quote(pipes.quote(arg)) for arg in args)
但这似乎不是一个干净的解决方案。
有人知道更好的将参数传递给 GNU Parallel 的方法吗?
谢谢!