rytone
rytone

Reputation: 165

GNU Parallel: Do not quote Perl replacement string values that contain spaces?

The script I am writing with parallel currently looks like this:

#!/bin/bash
seq ${2:-3} | parallel --tty -j0 sidplayfp -wch{}.wav '{=$_=join" ",map{"-u".$_}grep!/@{[seq()]}/,(1..total_jobs())=}' ${@:3} -q $1 '2>/dev/null'

For example, running ./sidrender.sh Stomp.sid is expected to execute the following commands:

sidplayfp -wch1.wav -u2 -u3 -q Stomp.sid 2>/dev/null
sidplayfp -wch2.wav -u1 -u3 -q Stomp.sid 2>/dev/null
sidplayfp -wch3.wav -u1 -u2 -q Stomp.sid 2>/dev/null

However, this does not work properly, and when looking with --dry-run, it turns out that parallel is quoting together the -u flags (e.g. sidplayfp -wch1.wav '-u2 -u3' -q Stomp.sid 2>/dev/null) because they come from the same Perl expression.

Here's a minimal example of what is happening:

$ parallel --dry-run 'echo {= $_="foo bar" =}' ::: 1
echo 'foo bar'

If you were to replace "foo bar" with "foo", the output would be echo foo without any quotes.

Because sidplayfp does not properly parse the arguments when they are quoted, I need a way to stop parallel from quoting the output, but I cannot find a way to do so in the man page.

Upvotes: 2

Views: 1682

Answers (1)

Ole Tange
Ole Tange

Reputation: 33685

Use eval:

seq ${2:-3} |
  parallel --tty -j0 eval sidplayfp -wch{}.wav '{=$_=join" ",map{"-u".$_}grep!/@{[seq()]}/,(1..total_jobs())=}' ${@:3} -q $1 '2>/dev/null'

Upvotes: 2

Related Questions