I have a script that reads a file line by line and does stuff based on what it reads. One of the things it does is ssh to a remote server and gets some information. For some reason that's completely beyond me, this stops the reading of lines from the file.
The script is essentially (I've cut out a lot of it to simplify the question, so don't worry if it looks like it doesn't really do anything):
cat $csv | while read line; do
shopt -s nocasematch
for j in "${file_list[@]}"; do
found=0;
for i in $(ssh some_server "ls /some_path/${line:0:1}/${line:1:1}/$line*"); do
if [[ $i =~ .*$j$ ]]; then
echo "do something";
found=1;
break;
fi;
done;
if [[ $found -ne 1 ]]; then
echo "don't have $j";
fi;
if [[ $found -ne 1 && $j == '\.pdf' ]]; then
getPDF $line ${dest};
fi;
done;
shopt -u nocasematch
done
This script winds up only running on the first line of the csv. If I replace the "ssh" part of the script with anything else though, it runs all the way through on all lines of the file. What gives?
read -rwhen doing line by line reading of a file, and you probably wantwhile IFS=$'\n' read -rat that if whitespace is important to you.