[Solved] Simple while loop does not exit

spath="/home/user/k/${1}"
dpath="/home/user/seq/Nov17/${1}"


cd $dpath
ls -1 $spath > list

c=1
while read list

newlist=`echo $list | sed 's/.gz//' `
newnewlist=`echo $newlist | sed 's/.fastq//' `

do

    echo $c
    echo $list
    c=$(($c+1))


done < list


The list has 96 lines but loop is going on and on. Please help

cd $dpath

c=1

newlist=`echo $list | sed 's/.gz//' `
newnewlist=`echo $newlist | sed 's/.fastq//' `

ls -1 $spath | while read LIST
do
    echo "$c"
    echo $LIST
    c=$(($c+1))
done 

Great! It works.

Do you have a minute to write a line to help me know the reson.
redirecting output to a file and then opening the file and reading does not work.
but when I pipe ls output directly to the loop, it works.

I would say its not a good idea to use the same name for a variable and a file when you use both in the same script... (For me it was already confusing...) Then of course there is this syntax error: a while expects straight after a "do".... So try your script again and use capital letters for your variables (after placing correctly the "do"). Does it work?

an12:/home/vbe $ while read LIST; do echo $LIST;sleep 1;done<list 
000
00aa
091102
091103
091104
091105
aa
about_dates.howto
about_sa1_sa2_sacd.txt
array001.sh
etc...

Yes it works.

This must be the reason. Thanks again

You welcome