From 47568071f068f4b45b691d0516953e97a9522bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20K=C3=BCgler?= Date: Sat, 13 Apr 2024 13:57:05 +0200 Subject: [PATCH 1/2] Remove strings from arithmetic expressions There seems to be an issue with parsing strings as integer/numbers in some bash versions, see #507 . This commit pulls out `num_subjects=${#subjects[@]}` and replaces the string `"${#subjects[@]}"` in the arithmetic expression by `num_subjects`. --- brun_fastsurfer.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/brun_fastsurfer.sh b/brun_fastsurfer.sh index d7114539..a438b54e 100755 --- a/brun_fastsurfer.sh +++ b/brun_fastsurfer.sh @@ -318,18 +318,19 @@ then fi fi +num_subjects=${#subjects[@]} if [[ -z "$task_id" ]] && [[ -z "$task_count" ]] then subject_start=0 - subject_end="${#subjects[@]}" + subject_end=$num_subjects elif [[ -z "$task_id" ]] || [[ -z "$task_count" ]] then echo "Both task_id and task_count have to be defined, invalid --batch argument?" exit 1 else - subject_start=$(((task_id - 1) * "${#subjects[@]}" / task_count)) - subject_end=$((task_id * "${#subjects[@]}" / task_count)) - subject_end=$((subject_end < "${#subjects[@]}" ? subject_end : "${#subjects[@]}")) + subject_start=$(((task_id - 1) * num_subjects / task_count)) + subject_end=$((task_id * num_subjects / task_count)) + subject_end=$((subject_end < num_subjects ? subject_end : num_subjects)) echo "Processing subjects $subject_start to $subject_end" fi subject_len=$((subject_end - subject_start)) @@ -488,4 +489,4 @@ then fi # always exit successful -exit 0 \ No newline at end of file +exit 0 From 5aa851b42e1173b582dd83c6e10992cd44817dab Mon Sep 17 00:00:00 2001 From: David Kuegler Date: Sat, 13 Apr 2024 14:14:57 +0200 Subject: [PATCH 2/2] Add version of the shell to the debug output --- brun_fastsurfer.sh | 3 ++- srun_fastsurfer.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/brun_fastsurfer.sh b/brun_fastsurfer.sh index a438b54e..480ff64d 100755 --- a/brun_fastsurfer.sh +++ b/brun_fastsurfer.sh @@ -288,7 +288,8 @@ then done echo "" echo "" - echo "Running in shell$(ls -l "/proc/$$/exe" | cut -d">" -f2)" + shell=$(ls -l "/proc/$$/exe" | cut -d">" -f2) + echo "Running in shell $shell: $($shell --version 2>/dev/null | head -n 1)" echo "" echo "---END DEBUG ---" fi diff --git a/srun_fastsurfer.sh b/srun_fastsurfer.sh index 676122aa..49065d56 100755 --- a/srun_fastsurfer.sh +++ b/srun_fastsurfer.sh @@ -489,7 +489,8 @@ do else debugf " %s" "$p"; fi done -debug "Running in$(ls -l /proc/$$/exe | cut -d">" -f2)" +shell=$(ls -l "/proc/$$/exe" | cut -d">" -f2) +debug "Running in shell $shell: $($shell --version 2>/dev/null | head -n 1)" debug "" if [[ "${pattern/#\/}" != "$pattern" ]]