0

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"
all_ids=()
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}"
fi
done

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
311_3T_T2w_SPC1.nii.gz

+ printf '%s\n' 100408 100610 101006 101107 101309 101410 101915 102008 102109 102311
+ parallel --jobs 6 --timeout 300% --progress recon-all -s '{.}' -all -qcache

1 Answers1

1

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!