- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- User Input within a while loop
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2002 08:51 PM
02-17-2002 08:51 PM
I have a while loop which reads three variables from a file.. and after some processing further down the program I am expecting the user to hit enter to continue...
"Press enter to continue ... " read
but, when I execute the program it doesn't stop where it is supposed to but just runs till the program finishes.. when I executed with debugging on... I found that the second read basically reads the three variables that I specified in the while loop.. ? How do I fix this ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2002 09:00 PM
02-17-2002 09:00 PM
Re: User Input within a while loop
It will be clearer if you show us the code you have written.
The stub should go something like this:
#!/sbin/sh
# while loop runs until end of file
cat file | while read var1 var2 var3
do
# process var1 var2 var3
echo $var1 $var2 $var3
echo "Press any key to continue\c"
read
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2002 09:16 PM
02-17-2002 09:16 PM
Re: User Input within a while loop
Please find attachment..
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2002 09:41 PM
02-17-2002 09:41 PM
SolutionThe command read reads from STDIN which is the input through the pipe
cat file | while ...
You can workaround this in your script as follows:
#!/sbin/sh
total=`cat inputfile|wc -l|awk '{print $1}'`
cnt=1
while [ "$cnt" -le "$total" ]
do
cat inputfile|tail +$cnt|head -1|read var1 var2 var3
print $var1 $var2 $var3
print "Press any key to continue...\c"
read
cnt=`expr $cnt + 1`
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2002 09:57 PM
02-17-2002 09:57 PM
Re: User Input within a while loop
Makes sense.. pretty neat workaround... I should have thought about this earlier :-)
-Shabu