【发布时间】:2011-11-22 16:22:49
【问题描述】:
我需要将一些包含空格和其他字符的文本传递给由 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 的更好方法吗?
谢谢!
【问题讨论】:
-
'不是一个干净的解决方案',但它有效吗?祝你好运。
标签: bash parallel-processing args