Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-24-2010, 10:59 AM   #1
LQ Newbie
Registered: Apr 2010
Posts: 8

Rep: Reputation: 0
catching keybord input

IS there a way to continue a script after "the any key" is pressed by a user?

I know there's the command "read" but then the input is put into a variable. Now i wan't to continue the script without comparing the user input.

I tried something like this:

echo "Press any key to continue"
read input

if [ $input = true ]; then
echo "Ok here we go"
Also with a wild card but it doesn't work properly.

Is there perhaps another way then with the "read" function?
Old 04-24-2010, 11:05 AM   #2
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
So you want to continue unconditionally if a key is pressed?

Try this:

echo "Press enter to continue"
echo "Ok here we go"
It must be Enter because the shell buffers input until Enter is pressed. And who ever said that you *have* to compare read's output in an if block?
Old 04-24-2010, 11:06 AM   #3
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Hi indur,

Please change your if statement to

if [ $input ]
Old 04-24-2010, 11:07 AM   #4
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Old 04-24-2010, 11:10 AM   #5
LQ Newbie
Registered: Apr 2010
Posts: 8

Original Poster
Rep: Reputation: 0
@ vinaytp

That simple!

Nice tnx!

@ MTK358

That was not wat i had in mind but tnx anyway.
Old 04-24-2010, 11:13 AM   #6
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
Please do not use texting shorthand here.


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
Catching keyboard meessages/input to a GTK(sharp) textview widget True_Friend Programming 0 07-13-2008 09:49 PM
keybord config. GlupFire Slackware 3 04-08-2008 05:21 PM
keybord ???????? joe108 Debian 1 08-06-2007 12:42 AM
Keybord not working ValidiusMaximus Linux - Laptop and Netbook 0 01-05-2005 05:07 PM
Keybord layer Getafix Linux - Newbie 0 10-11-2004 09:28 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration