I am trying to run bash script:

export LD_LIBRARY_PATH=/usr/lib/fsl/5.0:$LD_LIBRARY_PATH
export SUBJECTS_DIR=/output
timefmt="%C --- CPU:\t%E real,\t%U user,\t%S sys\t%P\tMem:\t%KkiBavg.,\t%MkiB max.\tExit:\t%x"
for dirname in /input/*; do

id=${dirname#/input/}    # remove "/input/sub-"
id=${id%/}             # remove trailing "/"

printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2
if [ ! -e "/output/$id" ]; then
    # no output file corresponding to this ID found,
    # add it to he list       
    all_ids+=( "$id" )
    /usr/bin/time -f "$timefmt" \
    recon-all -s "${id}" -i /input/${id}/unprocessed/3T/T1w_MPR1/${id}_3T_T1w_MPR1.nii.gz -i /input/${id}/unprocessed/3T/T2w_SPC1/${id}_3T_T2w_SPC1.nii.gz
    printf 'Series with t1 found, subjects matched: %s ; %s ; %s\n' "${id}"

printf 'Found ID: %s\n' "${all_ids[@]}" >&2

printf '%s\n' "${all_ids[@]}" | parallel --jobs 6 --timeout 300% --progress recon-all -s {.} -all -qcache

I made a docker container and it executed without any result, it just goes to the place and prints printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2, how ever if i run it with entrypoint=bash option with seperated command it executed properly.

Output of bash -x script.sh:

+ for dirname in '/input/*'
+ id=102311
+ id=102311
+ printf 'Adding ID to recon-all processing list: %s\n' 102311
Adding ID to recon-all processing list: 102311
+ '[' '!' -e /output/102311 ']'
+ all_ids+=("$id")
+ /usr/bin/time -f '%C --- CPU:\t%E real,\t%U user,\t%Ssys\t%P\tMem:\t%KkiB avg.,\t%MkiB max.\tExit:\t%x' recon-all -s 102311 -i /input/102311/unprocessed/3T/T1w_MPR1/102311_3T_T1w_MPR1.nii.gz -i /input/102311/unprocessed/3T/T2w_SPC1/102

+ printf '%s\n' 100408 100610 101006 101107 101309 101410 101915 102008 102109 102311
+ parallel --jobs 6 --timeout 300% --progress recon-all -s '{.}' -all -qcache
  • That's not a bash script. That's just a script, without a shebang, which means it will probably get executed by sh, unless you specify otherwise.
    – muru
    Jun 24 '19 at 15:48
  • @muru i tried to delete shebang, but it terminates with an error: Command terminated by signal 13 Jun 24 '19 at 15:59
  • 1
    You don't have a shebang, so how can you delete it?
    – muru
    Jun 24 '19 at 16:00
  • I mean I tried it both with a shebang and without a shebang Jun 24 '19 at 16:02
  • Post output of bash -x the_script.sh.
    – Ole Tange
    Jun 24 '19 at 19:11

Have you tried running shellcheck on your script and cleaning up the errors and warnings that come up? In my experience, doing this does wonders for the robustness and portability of my scripts.

Shellcheck has a website and is also available as an Open-Source (GPLv3) command-line tool.

Good luck!

Not the answer you're looking for? Browse other questions tagged or ask your own question.