Control Not Coming Out Of While Loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Control Not Coming Out Of While Loop
# 1  
Old 10-06-2008
Control Not Coming Out Of While Loop

I have an empty .gz file in archival directory. And I am redirecting to a dat file. My while loop is not getting ended. I need the solution.

cnt=0
while read line
do
cnt=`expr $cnt + 1`
echo "$ARCH_DIR/$line.gz" >> $DATA_DIR/$FILE_LIST_FILE_FEB
FILE_NAMES=${FILE_NAMES}" "${line}
done
# 2  
Old 10-06-2008
Code:
while read line
do 
    # do thing here
done < inputfile

Plus you cannot read a gz file directly - it is compressed into 'garbage' characters and is not human readable. Use zcat.

If you are entering numbers from the keyboard, to get the loop to stop, use ctrl-D
# 3  
Old 10-06-2008
Quote:
Originally Posted by vinodh1978
I have an empty .gz file in archival directory.

Do you? You are not doing anything with it in the script below.
Quote:
And I am redirecting to a dat file. My while loop is not getting ended. I need the solution.

Where is the loop getting its input? It will finish whenever the end of the input is reached.

If input is coming from the keyboard, press ^D.
Quote:

Code:
cnt=0
  while read line
  do
    cnt=`expr $cnt + 1`


You do not need an external command for integer arithmetic in the standard Unix shell:
Code:
cnt=$(( $cnt + 1 ))

Quote:
Code:
    echo "$ARCH_DIR/$line.gz" >> $DATA_DIR/$FILE_LIST_FILE_FEB
    FILE_NAMES=${FILE_NAMES}" "${line}


The usual idiom is:
Code:
    FILE_NAMES="$FILE_NAMES $line"

Quote:
Code:
  done

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a control file loop

Hi, Let's say I have a control file like this: RHEL apple "echo apple" RHEL bravo "ls -l bravo*" RHEL church "chmod church.txt" SUSE drive "chown user1 drive.txt" SUSE eagle "echo "eagle flies"" SUSE feather "ls -l feather*" HP-UX google "sed 's/^Google.*$/&\ ACTION: go to... (14 Replies)
Discussion started by: The Gamemaster
14 Replies

2. Infrastructure Monitoring

Notifications not coming through

Issue: I'm not receiving notifications I can succesfully receive an e-mail if I do this on the command line: /usr/bin/mail -s "NAGIOS HOST ALERT on $HOSTNAME$" rgouette@butlerbros.com but, my command.cfg configuration below, refuses to send an e-mail when I set a service to a critical... (3 Replies)
Discussion started by: rgouette
3 Replies

3. UNIX for Dummies Questions & Answers

coming out from vi editior

Hi Folks, I have opened a log file through Vi editor in putty itself and I was searching for a pattern in logs , let say 'ABCD' /abcd then I want to come out from vi editor, Please advise what is the command to come out from unix editor..! (1 Reply)
Discussion started by: KAREENA18
1 Replies

4. Shell Programming and Scripting

Loop exit control

Hi I would like to exit the loop below on <Enter> even if it sleeps. Is it possible? while true do my_procedure; sleep 60 done Thanks (7 Replies)
Discussion started by: zam
7 Replies

5. UNIX for Dummies Questions & Answers

For loop control with two variables in csh shell

Hi All How can i control for loop with two different variables in csh shell Regards Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

6. Shell Programming and Scripting

for loop control

Hi, I have taken a piece of code from a book, which is working as per the specification. The code.... for entry in * do if then echo $entry fi done The sub-directories present in the current directory will be displayed while executing. ... (3 Replies)
Discussion started by: saravanakumar
3 Replies

7. Shell Programming and Scripting

find command in while loop - how to get control when no files found?

I have the following statement in script: find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN2} -print | while read file; do ... done When there are no files located by the find comand it returns: "find: bad status-- /home/rnitcher/test/....." to the command line How do I get control in... (3 Replies)
Discussion started by: mavsman
3 Replies

8. Shell Programming and Scripting

sending control c in the loop

I want to go through the list of items and run it. while running it, some of them will have either >there is no response # and then end it... so that it can go to next item OR >there is response # but in order to break out of it, u need to do Control c. How do you send control... (6 Replies)
Discussion started by: hankooknara
6 Replies
Login or Register to Ask a Question