Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
0
0
DE
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 ... :-(

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

Best Regards,
Thomas
 
Hi

Irrelevant what you press, that will always evaluate to true :
Code:
[blue]master #[/blue] key='Q'; [ $key = "Q" -o "q" ]; echo $?
0

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

[blue]master #[/blue] 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 2[sup]nd[/sup] part of expression to ever be anything else but true.

Maybe you want this instead :
Code:
[teal][[/teal] [navy]$key[/navy] [teal]=[/teal] [i][green]"Q"[/green][/i] -o [highlight][navy]$key[/navy] [teal]=[/teal][/highlight] [i][green]"q"[/green][/i] [teal]][/teal]

Feherke.
feherke.ga
 
My goodness, must have been too much code for me lately so I missed the fact that I forgot the second $key ... ;-)

Thanks a lot ! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top