parallel
[Top][All Lists]
Advanced

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

User opinion needed: What shell should GNU Parallel use?


From: Ole Tange
Subject: User opinion needed: What shell should GNU Parallel use?
Date: Fri, 23 May 2014 14:43:51 +0200

Matt Thompson raises a general problem: Which shell should commands
run under in GNU Parallel?

All design decisions in GNU Parallel are heavily based on POLA. If
there was no obvious choice it, I have focused on the interactive use
(as opposed to use in scripts), because I primarily use GNU Parallel
interactively.

But the shell question should probably be given some more thought, and
I need your help for that.

If I run this under Bash I get:

    $ echo $version; echo $BASHPID

    13563

If I run the same under tcsh I get:

    ~> echo $version; echo $BASHPID
    tcsh 6.18.01 (Astron) 2012-02-14 (x86_64-unknown-linux) options
wide,nls,dl,al,kan,rh,nd,color,filec
    BASHPID: Undefined variable.

It is not really surprising that if I use Bash'ism or tcsh'ism then
these give different output.

But what should I get if I run the same using GNU Parallel:

    $ parallel '{} $version; {} $BASHPID' ::: echo

Right now GNU Parallel uses $SHELL. This is under the assumption that
the user's login shell is the one he will mostly use. And based on
POLA running the same command under GNU Parallel should give the same
output as not running it under GNU Parallel.

If you are using Bash normally, POLA suggests you should get this:

    $ parallel '{} $version; {} $BASHPID' ::: echo

    13563

And if you are using tcsh normally, POLA suggests you should get this:

    ~> parallel '{} $version; {} $BASHPID' ::: echo
    tcsh 6.18.01 (Astron) 2012-02-14 (x86_64-unknown-linux) options
wide,nls,dl,al,kan,rh,nd,color,filec
    BASHPID: Undefined variable.

This is how GNU Parallel works now. But here comes the tricky part:
What should GNU Parallel do, if you run the command in a script?

If a script contains:

    parallel '{} $version; {} $BASHPID' ::: echo

then the actual behaviour will depend on whether you have tcsh or Bash
as your login shell. The big problem arises if someone else wrote the
script, and you do not know that GNU Parallel is being used in the
script. Then the script will behave very differently depending on your
login shell. And this will not adhere to POLA.

One idea is to let it depend on which shell it is currently running
under: If the script starts with #!/bin/bash or #!/bin/tcsh then use
that shell. It will also make sense if, say, your login shell is tcsh,
but the first thing you do is to start Bash. I am not really sure how
to detect that, but it can probably be done.

It leaves a corner case: namely if GNU Parallel is called using
#!/usr/bin/parallel --shebang.

Ideas? Thoughts? Suggestions?


/Ole



reply via email to

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