5

The command parallel echo {} ::: A B C executed from the command line return the correct result, while when invoked within a bash script return the error:

This is the script:

#script.bash
#!/usr/bin/env bash

parallel echo {} ::: A B C

This is the output:

bash script.bash
/bin/bash: {}: command not found
/bin/bash: ::: command not found
/bin/bash: A: command not found
/bin/bash: B: command not found
/bin/bash: C: command not found

Any idea why and how to correctly call GNU parallel within a bash script?

memecs
  • 7,196
  • 7
  • 34
  • 49

1 Answers1

6

Apparently the --tollef switch (that does not support the ::: syntax) gets enabled when you run it from a script.

You can fix it either by enabling the --gnu switch as with

parallel --gnu echo {} ::: A B C
user000001
  • 32,226
  • 12
  • 81
  • 108
  • For example: parallel echo {} $JOBID ::: $(ls), would produce 1,2,3,4. Similar to LSB_JOBINDEX on LSF – memecs Jan 13 '14 at 12:29
  • @memecs No I haven't seen anything like that on gnu parallel. That does not mean that it does not exist though :) – user000001 Jan 13 '14 at 12:31
  • If it exists it's difficult to find... :). Anyway, thanks a lot for you help – memecs Jan 13 '14 at 12:32
  • Well, it could be achieved with: parallel --xapply echo {0} {1} ::: $(ls) ::: $(seq 0 $(ls | wc -l)). Much more teadious though – memecs Jan 13 '14 at 12:36
  • 2
    See {#} in man. Also walk through the tutorial: http://www.gnu.org/software/parallel/parallel_tutorial.html – Ole Tange Jan 13 '14 at 16:01
  • @memecs It looks like Ole found what you were looking for – user000001 Jan 13 '14 at 18:42
  • 1
    @user000001 is --tollef enabled even if you've deleted the option from the file /etc/parallel/config or deleted the config file entirely? On my system that doesn't happen (though I was burned by the --tollef flag in the past, before deleting the config file). See also: http://stackoverflow.com/a/16448888/868718 – Steve Koch Jan 13 '14 at 22:16
  • @SteveKoch It wasn't deleted on my laptop, which is why I was able to reproduce the problem, and answer the question :) – user000001 Jan 13 '14 at 22:58
  • @user000001 Thanks! I was worried that the flag would be enabled depending on how I ran parallel--good to know that's not the case :) – Steve Koch Jan 13 '14 at 23:14