1

I'm running gnu-parallel on a command that works fine when run from a bash shell but returns an error when parallel executes it with bash using the -c flag. I assume this has to do with the special globbing expression I'm using.

ls !(*site*).mol2

This returns successfully.

With the flag enabled the command fails

/bin/bash -c 'ls !(*site*).mol2'
/bin/bash: -c: line 0: syntax error near unexpected token `(' 

The manual only specifies that -c calls for bash to read the arguments for a string, am I missing something?

Edit: I should add I need this to run from a gnu-parallel string, so the end resultant command must be runnable by /bin/bash -c "Some Command"

RussS
  • 16,476
  • 1
  • 34
  • 62

1 Answers1

4

You should try the following code :

bash <<EOF
shopt -s extglob
ls !(*site*).mol2
EOF

Explanation :

when you run bash -c, you create a subshell, and shopt settings are not inherited.

EDIT

If you really need a one liner :

bash -O extglob -c 'ls !(*site*).mol2'

See this thread

Community
  • 1
  • 1
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • You may want to use a single-quoted here document separator `bash <<'EOF'` lest the calling shell interpolates some of the special characters. Or you could stick to your original `bash -c` approach and just add `shopt -s extglob;` before any commands. – tripleee Oct 09 '12 at 20:45
  • Depends of the need of the OP, but I will add something for that – Gilles Quénot Oct 09 '12 at 20:46
  • @sputnick That is definitely what I want but I don't know how to add arguments to Parallel's default calling command which is /bin/bash -c "" – RussS Oct 09 '12 at 20:52