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????
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????
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.
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...
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....
#!/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