我正在尝试运行 bash 脚本:
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
我制作了一个 docker 容器,它执行时没有任何结果,它只是转到该位置并打印printf 'Adding ID to recon-all processing list: %s\n' "${id}" >&2
,但是如果我使用 Entrypoint=bash 选项和单独的命令运行它,它会正确执行。
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
您是否尝试过在脚本上运行 shellcheck 并清除出现的错误和警告?根据我的经验,这样做对于我的脚本的稳健性和可移植性来说确实有奇迹。
外壳检查有一个网站并且还可以作为开源 (GPLv3) 命令行工具使用。
祝你好运!