bug-parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNU Parallel Bug Reports First read of {} has strange behavior


From: Ole Tange
Subject: Re: GNU Parallel Bug Reports First read of {} has strange behavior
Date: Sat, 2 Aug 2014 18:18:50 +0200

On Fri, Aug 1, 2014 at 8:14 PM, Zachary Vance <address@hidden> wrote:
> parallel --version
> GNU parallel 20140722
>
> parallel has strange behavior with {} on occasion:
> echo -e "a\nb\nc" | parallel -I {} -- bash -c "echo {} && echo {} && echo
> {}"
:
> xargs does not:
> echo -e "a\nb\nc" | xargs -I {} -- bash -c "echo {} && echo {} && echo {}"
:
> Why is this happening? Is it a bug or just a difference of interface I'm not
> understanding?

It is due to quoting. GNU Parallel generally needs less quoting than
xargs. So you do not need to wrap the script in bash -c:

    echo -e "a\nb\nc" | parallel "echo {} && echo {} && echo {}"

If you insist on wrapping with bash -c, then the first 'echo' and {}
will be handed to bash -c as TWO arguments, which is clearly not what
you meant. This is clearer if you run parallel with -v:

    echo -e "a\nb\nc" | parallel -v -I {} -- bash -c "echo {} && echo
{} && echo {}"

To rectify this you can ask GNU Parallel to quote every single arg as
single args to the command:

    echo -e "a\nb\nc" | parallel -q -I {} -- bash -c "echo {} && echo
{} && echo {}"

But using -q will make commands like this fail:

    echo -e "a\nb\nc" | parallel -q "echo {} && echo {} && echo {}"

and make commands like this behave surprisingly:

    echo -e "a\nb\nc" | parallel -q echo "{} && echo {} && echo {}"

Personally I find the shorter version easier to read:

    echo -e "a\nb\nc" | parallel "echo {} && echo {} && echo {}"

And you only need to quote the special shell chars:

    echo -e "a\nb\nc" | parallel echo {} '&&' echo {} '&&' echo {}

which is handy if you really need ' and " for quoting other stuff.

If your script is much more advanced that 3 echos, then consider
making a bash function, export -f it, and use that from GNU Parallel.
It makes quoting SOO much easier.


/Ole



reply via email to

[Prev in Thread] Current Thread [Next in Thread]