LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-10-2011, 10:44 PM   #1
mikedotexe
LQ Newbie
 
Registered: Feb 2011
Posts: 1

Rep: Reputation: 0
Unhappy "read" is reading info from while loop


Hey guys, I'm trying to prompt the user to enter Y or N in the middle of a while loop, but the read command is simply drawing in the next value.

I'm reading from a simple file full of words (one per line)

Code:
while read line
do
	echo $line
	grep $line dict #check if its in dictionary file
	if [ $? -ne 1 ]
	then
		echo Match found
	else
		echo "Would you like to add '$line' to the dictionary? (Y / N)"
		read promptadd
		echo "you said $promptadd"
	fi
done < myfile
The read line automatically takes the value of the next word from the file here. How do I interrupt and make it so the user is prompted?

Mahalo

Last edited by mikedotexe; 02-10-2011 at 10:45 PM.
 
Old 02-10-2011, 11:07 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,442

Rep: Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880
Remembering that read takes its information from standard in which you have redirected to come from a file, you will need to setup some file descriptors
so you can tell the different reads where to get their information from.

Take a look here if you are not sure where to start
 
  


Reply

Tags
sh, shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fsck.ext3 keeps fails with "Error reading block" short read at same block jpletka Linux - Server 2 06-10-2010 02:46 AM
[SOLVED] "while read line" doesn't work with ssh in the loop body asemaany Programming 5 03-28-2010 01:14 AM
Error reading block "x" (Attempt to read block from....... pvandyk2005 Slackware 6 07-06-2008 05:25 AM
"Permission denied" and "recursive directory loop" when searching for string in files mack1e Linux - Newbie 5 06-12-2008 07:38 AM
..."short read while reading block 516" mohapi Fedora 7 10-22-2004 01:37 PM


All times are GMT -5. The time now is 10:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration