How do I run multiple commands with the --quote
/-q
option?
For example, this quotes the ;
:
$ 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
¿How do I unquote it so that it runs:
command1 'With a space' ; command2
command1 'Another space' ; command2
command1 'Yet more spaces' ; command2
I know my MWE here probably doesn't need -q
, but when I have more complicated commands with arguments that need quotes, I ran into the issue that single quotes Parallel put were "leaking" through into the text passed to the command.
You have already given the solution: remove -q, and addressed the problem, that this raises:
when I have more complicated commands
https://www.gnu.org/software/parallel/man.html#quoting says:
Conclusion: If this is confusing consider avoiding having to deal with quoting by writing a small script or a function (remember to export -f the function) and have GNU parallel call that.
You can still use GNU Parallel to generate the arguments.
So:
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} ::: */* ::: "double space" "triple space" " 4 spc"
IMHO it often improves readability, too.