LinuxQuestions.org
Visit the LQ Articles and Editorials section
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

Closed Thread
 
Search this Thread
Old 04-01-2013, 05:10 PM   #1
yarock
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Rep: Reputation: Disabled
Question wait a keypress by using the command read


Hi, at a certain point in my bash script, I want to wait for a key pressed on the keybord. I searched on the net and I found that I should use the command read -s -n 1 . Here is the format of my script:

#########################################
1- while read var1 var2
2- do
3- echo "hello"
4-
5- if [ var3 -eq var4 ]; then #var3 and var4 are defined before
6- echo "Press any key to continu"
7- read -s -n 1
8- fi
9-
10- done < data.txt
##########################################

My problem is that when the script execute the line 7, instead of waiting for a keypress, it use the next caracter of data.txt and it continu until the end of the file data.txt. How can I force it to use a keypress?
 
Old 04-01-2013, 05:13 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045Reputation: 4045
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread


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
wait a keypress using the command read yarock Programming 5 04-01-2013 09:39 PM
looking to induce high i/o read/wait for testing gargunkle Linux - Software 1 11-29-2011 08:28 PM
[SOLVED] Read from stdin in perl, do not wait for EOF smeezekitty Programming 1 04-28-2010 03:17 PM
Does Kornshell wait until one command completes before running the next command? ShaqDiesel Programming 4 09-10-2008 11:49 PM
wait for x seconds type command sub-genius Slackware 1 07-14-2003 07:11 PM


All times are GMT -5. The time now is 09:07 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