LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   catching keybord input (https://www.linuxquestions.org/questions/linux-newbie-8/catching-keybord-input-803943/)

indur 04-24-2010 09:59 AM

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"
fi
Also with a wild card but it doesn't work properly.

Is there perhaps another way then with the "read" function?

MTK358 04-24-2010 10:05 AM

So you want to continue unconditionally if a key is pressed?

Try this:

Code:

echo "Press enter to continue"
read
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?

vinaytp 04-24-2010 10:06 AM

Hi indur,

Please change your if statement to

Code:

if [ $input ]

smoker 04-24-2010 10:07 AM

http://tldp.org/LDP/abs/html/internal.html#EX36

indur 04-24-2010 10:10 AM

@ vinaytp

That simple! :)

Nice tnx!

@ MTK358

That was not wat i had in mind but tnx anyway.

pixellany 04-24-2010 10:13 AM

Please do not use texting shorthand here.
what
thanks


All times are GMT -5. The time now is 04:12 PM.