LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   wait a keypress by using the command read (https://www.linuxquestions.org/questions/linux-newbie-8/wait-a-keypress-by-using-the-command-read-4175456430/)

yarock 04-01-2013 06:10 PM

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?

TobiSGD 04-01-2013 06:13 PM

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.


All times are GMT -5. The time now is 01:43 PM.