problem in reading inside a while loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers problem in reading inside a while loop
# 1  
Old 08-06-2008
problem in reading inside a while loop

I am not able to read inside a while though i get the message "inside read" the cursor doesnt prompt from the console

cat file | while read ln_new_engine_dirs
do
echo "inside $ln_new_engine_dirs"
if [ "$ln_new_engine_dirs" != "" ]
then
read nn
echo "inside read"
fi
done
Thanks in advance
# 2  
Old 08-06-2008
Quote:
Originally Posted by ssuresh1999
I am not able to read inside a while though i get the message "inside read" the cursor doesnt prompt from the console
Code:
 
cat file | while read ln_new_engine_dirs
do
echo "inside $ln_new_engine_dirs"
if [ "$ln_new_engine_dirs" != "" ]
then
read nn 
echo "inside read"
fi
done


You are reading from the standard input which is coming from file. You need to read from the terminal, e.g.:
Code:
read nn < /dev/tty

# 3  
Old 08-07-2008
Quote:
Originally Posted by cfajohnson
You are reading from the standard input which is coming from file. You need to read from the terminal, e.g.:
Code:
read nn < /dev/tty

Thank you very much it works Smilie
# 4  
Old 08-07-2008
Thank you very much it works Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies

2. Shell Programming and Scripting

Problem with while loop reading every line of a text file

Hello, I'm using RHEL 5.1 with bash. How to handle "read" inside while loop reading every line? Please see below: # cat /tmp/passwd_sample CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash... (4 Replies)
Discussion started by: reddyr
4 Replies

3. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

4. Shell Programming and Scripting

Problem passing a search pattern to AWK inside a script loop

Learning, stumbling! My progress in shell scripting is slow. Now I have this doubt: I have the following file (users.txt): AU0909,on AU0309,off AU0209,on AU0109,off And this file (userson.txt) AU0909 AU0209 AU0109 AU0309 I just want to set those users on userson.txt to "off" in... (14 Replies)
Discussion started by: quinestor
14 Replies

5. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

6. Shell Programming and Scripting

Problem reading file in while/read loop

I know I should be able to see a way of doing this easily, but my brain just won't engage. I have a script working on an embedded device that checks to see if an item is in a blacklist before performing some actions. At the moment the code reads thus.... while read BLACKLIST ; do ... (7 Replies)
Discussion started by: Bashingaway
7 Replies

7. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. UNIX for Dummies Questions & Answers

Reading inside a loop

Hi I am trying read in side a do statement but it is not working it is just printing abc before read but not stopping in abc for user input Can anybody please help #!/usr/bin/ksh cat sample_file | while read ln_source3 do param=`echo $ln_source3 | nawk... (1 Reply)
Discussion started by: ssuresh1999
1 Replies

9. Shell Programming and Scripting

reading from within the loop --std i/p problem

i have a teat file having data like one 12/3 two 23/09 three 12/12 now from another script i want to read one line at a time ,cut field one and two in two separate variable ,compare field1 with another variable but outside the loop .If i found a match i want to take from user the value... (2 Replies)
Discussion started by: mobydick
2 Replies

10. UNIX for Dummies Questions & Answers

reading filenames inside a program

UNIX Sun Ultra60 5.5.1 Hello everybody, I have a problem that seems simple but turns out to be complex (for me at least). My program needs to open a directory (this part is easy), scan each filename and determine whether or not a file with the suffix (.07) exists. So the program would return... (5 Replies)
Discussion started by: j_t_kim
5 Replies
Login or Register to Ask a Question