LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Clearing the standard input in shell script (https://www.linuxquestions.org/questions/linux-software-2/clearing-the-standard-input-in-shell-script-905584/)

Diptendu 09-29-2011 06:38 AM

Clearing the standard input in shell script
 
I have a shell script, having more than one user input.
I want to clear/flush the stdin before the read command, as it is creating problem if user pressed more than one enter key for one read.

Code:

#!/bin/sh

echo "Give input"

read -p ":>" FirstInput

sleep 1

echo "Given value: $FirstInput"

# Here I want to flush the input before reading the user input again.

read -p ":> " SecondInput
echo "Given value: $SecondInput"


colucix 09-29-2011 07:33 AM

You might try to put
Code:

read -t0
after the first read statement (before sleep). In this way any other additional input is immediately and silently ignored.


All times are GMT -5. The time now is 06:54 PM.