Dockerコンテナ内でBashスクリプトを正しく実行できません。

Dockerコンテナ内でBashスクリプトを正しく実行できません。

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}" >&2Entrypoint = 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)コマンドラインツールとしても使用できます。

頑張ってください!

おすすめ記事