bug-parallel
[Top][All Lists]
Advanced

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

GNU Parallel Bug Reports Unexpected execution of /bin/sh when SHELL or P


From: Zhiming Wang
Subject: GNU Parallel Bug Reports Unexpected execution of /bin/sh when SHELL or PARALLEL_SHELL is bash
Date: Fri, 20 Nov 2015 14:27:59 -0800

Consider the following script named 'test':

    #!/bin/bash
    func () {
        echo $BASH
        cat <(echo 'hello, world');
    }
    export -f func
    SHELL=/bin/bash parallel ::: func

When the script is executed in OS X (where /bin/sh is bash in sh emulation
mode; see
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sh.1.html):

    > ./test
    sh: func: line 1: syntax error near unexpected token `('
    sh: func: line 1: ` cat <(echo 'hello, world')'
    sh: error importing function definition for `func'
    /usr/local/bin/bash
    hello, world

One can immediately spot two issues here:

1.  Errors printed by sh. Bash-emulated sh tries to import exported functions
    anyway (which I see as a defect), but sh doesn't have process substitution,
    hence the errors. However, *why is /bin/sh called in the first place?*

    Note that 'func' is successfully executed despite the error messages, and
    the value of $BASH is /usr/local/bin/bash instead of /bin/sh, so bash is
    executed after all.

    Also note that the error messages are only reproducible on systems where
    /bin/sh is bash. For instance, Debian's /bin/sh is dash, which doesn't try
    to import exported functions in bash, so one won't see the error messages
    on Debian.

2.  Although the parent shell and $SHELL are both /bin/bash, the shell that
    gets executed in the end is /usr/local/bin/bash, which seems to contradict
    the $PARALLEL_SHELL part of the man page, according to which the shell is
    determined in the following order:

        * $PARALLEL_SHELL;
        * The shell that started GNU Parallel (if it can be determined);
        * $SHELL;
        * /bin/sh.

    Replacing 'SHELL=/bin/bash parallel ::: func' with
    'PARALLEL_SHELL=/bin/bash parallel ::: func' leads to /bin/bash in the
    output, as expected (it doesn't suppress the error messages by sh).

    This issue is reproducible on Linux, too.

Best,
Zhiming

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail


reply via email to

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