[Solved] Simple while loop does not exit


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Simple while loop does not exit
# 1  
Old 12-06-2011
[Solved] Simple while loop does not exit

Code:
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

Last edited by analyst; 12-06-2011 at 12:09 PM..
# 2  
Old 12-06-2011
Code:
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

This User Gave Thanks to vbe For This Post:
# 3  
Old 12-06-2011
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.
# 4  
Old 12-06-2011
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?
# 5  
Old 12-06-2011
Code:
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...

# 6  
Old 12-06-2011
Quote:
Originally Posted by vbe
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?
Yes it works.

This must be the reason. Thanks again
# 7  
Old 12-06-2011
You welcome
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Perl, Deep recursion? exit() ignored?

Hi all, I am calling a subroutine which checks if a log file is writeable and if not, prints something stdout and also log something into the same file, which doesn't work neither of course. Anyway, there is enough exit() calls, that should stop it working, but the problem is, that I get the... (5 Replies)
Discussion started by: zaxxon
5 Replies

2. Shell Programming and Scripting

[Solved] Rsh does not close connection on exit

Dear all, We have a service that we start up remotely with rsh but unfortunately, the rsh never returns to the calling server. This seems to be because the processes of the service we've just started hold the port open.RBATTE1 @ /home/RBATTE1>netstat -na|grep 49.51 tcp4 0 0 ... (1 Reply)
Discussion started by: rbatte1
1 Replies

3. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

4. Emergency UNIX and Linux Support

For loop exit

Below for loop not exiting. Can someone help? JBOSS_INST_ARGS=01 02 if ; then for i in $JBOSS_INST_ARGS; do /u/jboss-6.1.0.Final/bin/jboss_init_wise$i.sh start; done (8 Replies)
Discussion started by: vino_hymi
8 Replies

5. HP-UX

[Solved] ssh debug1: Exit status 254 problem

Hello; Am experiencing odd problem with ssh: ========= ssh -vvv remote_host : : debug2: channel 0: rcvd adjust 65536 debug2: channel_input_status_confirm: type 99 id 0 debug2: shell request accepted on channel 0 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0... (4 Replies)
Discussion started by: delphys
4 Replies

6. Shell Programming and Scripting

[Solved] Strucked in Simple if

Whats the wrong with the following code: if ; then echo "File XYZ Exist" if ] ; then echo "File abc is not empty, script continues" else echo "File abc is empty, script aborts" exit 0 fi else echo "File XYZ does not exist" exit 0 Error: testscript.ksh:... (3 Replies)
Discussion started by: karumudi7
3 Replies

7. Shell Programming and Scripting

Strange exit of while loop

This code is used to check for duplicate ip and hostnames in an /etc/hosts file CENTRAL is path to /etc/hosts AWK =awk #check CENTRAL for duplicate ips or hostnames# grep -v "^#" $CENTRAL | $AWK '{ print $1, $2; }' | \ while read ip hostname do if... (5 Replies)
Discussion started by: trimike
5 Replies

8. Shell Programming and Scripting

Exit from loop

hi, how to exit from "if" loop?actually i have mutliple "if" conditions, i have to exit from each "if" loop,if it is true...:confused: Please suggest me... (3 Replies)
Discussion started by: sreelu
3 Replies

9. Shell Programming and Scripting

exit out of a while loop with error

im running a while loop as a file watcher, with incremental counter on the retries..however when the retries reach it's limit i want it exit and echo and error and stop the batch. Im not sure the code i have will do that already... Here is what i have that works: #!/usr/bin/ksh count=0... (2 Replies)
Discussion started by: sigh2010
2 Replies

10. Shell Programming and Scripting

while loop exit

i wrote a while script as part of a huge program. this script, once picked, begins to output data to the person using it. pretty easy, as the person doesn't have to keep typing commands to get the output that the while loop automatically throws out. now, the thing is, while this while-script... (3 Replies)
Discussion started by: Terrible
3 Replies
Login or Register to Ask a Question