I trying to run command recon-all with GNU parallel freesurfer preproc i have a bash array of list of patients to run 8 patents simultaneously:

root@4d8896dfec6c:/tmp# echo ${ids[@]}
G001 G002 G003 G004 G005 G006 G007 G008

and try to run with command:

echo ${ids[@]} | parallel --jobs 28 recon-all -s {.} -all -qcache

it doesn't work because i suppose i need to have bash array in ls representation, smth like:

ls ${ids[@]} | parallel --jobs 28 recon-all -s {.} -all -qcache

How can i do that?

2 Answers 2


If the ids fits on a single command line:

parallel --jobs 28 recon-all -s {.} -all -qcache ::: "${ids[@]}"

Else like Lucas suggests:

printf %s\\n "${ids[@]}" | parallel --jobs 28 recon-all -s {.} -all -qcache

The problem is that parallel wants the input to be separated by newlines but when you use echo it is separated by spaces. In order to print some words separated by newlines you can try one of these

echo one two three | tr ' ' '\n'    # in case your input can not be controlled by you
printf '%s\n' one two three         # if you can control the words eg if you have an array

So you should probably do it like this:

printf '%s\n' "${ids[@]}" | parallel --jobs 28 recon-all -s {.} -all -qcache

Remember to quote your array substitutions and variables in general in order to prevent accidental word splitting and other side effects if your values contain special characters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .