super new to bash
I wrote a bash script that works perfectly on one MAC but doesn't on a different MAC.
The code iteratively cycles through subjects' folders, copies the data, performs some function, deletes the copied data, then moves to the next subject. To do so, I call a text file that contains the subject names, which informs the script to select the corresponding subject folder (using the variable $mri_path
in the code below).
The problem is, on this new MAC- the script can't find the subject's folder using a text file- error code: file/directory does not exist. A main difference between MACs is the text file being used- it contains different subject names. I can hardcode the script to find the subjects' folders, so this leads me to suspect the text file is not being read correctly.
I have tried different text file formats (e.g., unicode, Macintosh formatted, tab delimited)... so I don't know why the script can't find the subject folders.
Reduced code:
#!/bin/bash
#usage: ./dcm2nii_batch.sh subj.txt startline endline
s1=$(($2-1))
s2=$(($3-1))
vars=($(awk -F= '{print$1}' subj.txt));
for ((i=s1; i<s2; i++));
do mri_path=${vars[$i])};
echo $mri_path;
echo '***';
cd /Users/syschaef/Desktop/dcm2nii_batch/Raw/$mri_path
The error occurs at the last line as the cd
command fails.
The text file data are subject identifying numbers that correspond to subject folder names/directories (screenshot):
I appreciate you taking the time to read and/or respond!