LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-29-2011, 07:38 AM   #1
Diptendu
LQ Newbie
 
Registered: May 2006
Posts: 1

Rep: Reputation: 0
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"
 
Old 09-29-2011, 08:33 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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.
 
  


Reply


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
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 01:46 PM
shell script question,standard input,output,error cola Programming 4 04-15-2010 02:11 AM
Help Please - averging input in a shell script reddawn Linux - Newbie 2 07-16-2006 02:44 PM
How to append characters to standard input (telnet script) cep21 Linux - General 1 07-10-2006 02:02 PM
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 04:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:46 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration