×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

"Press any key to continue" function ... Problem when <Enter> is pressed ...

"Press any key to continue" function ... Problem when <Enter> is pressed ...

"Press any key to continue" function ... Problem when <Enter> is pressed ...

(OP)
Hi everyone,

I included the following function into my latest script:

CODE

function fkt_continue
{
echo "\033[1;36mPress any key to continue (or <Q> to quit) ...\033[m"
stty -echo
stty raw
key=$(dd bs=1 count=1 2> /dev/null) > /dev/null
stty echo
stty -raw
if [ $key = "Q" -o "q" ];
 then
  exit 1
fi
} 

So far so good and everything works fine except when you press the <Enter> key it will act like Q has been pressed and quit the script ... sad

Any ideas why that's so and what I can do about it ?

Best Regards,
Thomas

RE: "Press any key to continue" function ... Problem when <Enter> is pressed ...

Hi

Irrelevant what you press, that will always evaluate to true :

CODE --> command line

master # key='Q'; [ $key = "Q" -o "q" ]; echo $?
0

master # key='q'; [ $key = "Q" -o "q" ]; echo $?
0

master # key='TSch'; [ $key = "Q" -o "q" ]; echo $?
0 
There you wrote value of variable $key equals string "Q" or string "q" is not empty. I can not imagine the 2nd part of expression to ever be anything else but true.

Maybe you want this instead :

CODE --> shell ( fragment )

[ $key = "Q" -o $key = "q" ] 

Feherke.
feherke.ga

RE: "Press any key to continue" function ... Problem when <Enter> is pressed ...

(OP)
My goodness, must have been too much code for me lately so I missed the fact that I forgot the second $key ... winky smile

Thanks a lot ! smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close