The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rsh script with inside a for loop trekianov Shell Programming and Scripting 5 12-06-2008 12:39 PM
Checking condition inside the loop ithirak17 Shell Programming and Scripting 1 03-13-2008 08:37 AM
remsh inside of while loop joettacm UNIX for Advanced & Expert Users 1 12-07-2007 12:54 PM
ls while read loop - internal read picking up wrong input dkieran Shell Programming and Scripting 2 05-14-2007 03:02 PM
input inside while read loop jhansrod Shell Programming and Scripting 3 08-13-2005 10:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-21-2005
dta4316 dta4316 is offline
Registered User
  
 

Join Date: May 2005
Posts: 3
read inside a while loop

Hi all,

In a while loop, like below...

while read line
do
read choice

case $choice in
1)
echo "xxx"
esac


done < file
why I can't run the read choice????
  #2 (permalink)  
Old 05-21-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Thumbs up

instead of simple read use

read response < /dev/tty

Because as the default stream in while has been associated with the file, read will not read from terminal.

Note: Redirecting terminal will slowen ur script a bit as it is heavy on resources.
  #3 (permalink)  
Old 05-21-2005
nj_2000 nj_2000 is offline
Registered User
  
 

Join Date: May 2005
Posts: 1
Hi Dta,

I too have same problem...i am getting "line" value into "choice" and not getting the input from terminal.

I am looking for a soultion to use "read" twice in a while loop.

Thanks...
  #4 (permalink)  
Old 05-21-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Rather than wrestling with the shell to do this - make it easy on yourself and use Perl - for example, to only print the line if the user enters a 1....
Code:
#!/usr/bin/perl

open( FOOFILE, "< foofile" );
while( <FOOFILE> ) {
  print( "Enter a number: " );
  chomp( $input = <STDIN> );
  if ( $input == 1 ) {
    print( "You entered a 1 and the line is $_" );
  } else {
    print( "Ooops - not a 1\n" );
  }
}
close( FOOFILE );
Cheers
ZB
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0