LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-05-2009, 08:58 PM   #1
manwithaplan
Member
 
Registered: Nov 2008
Location: ~/
Distribution: Arch || Sidux
Posts: 393

Rep: Reputation: 45
BASH --> esc key in a case statement


This is just an example... I would like it when I press "esc" "^]" to exit and run my leavin function. But it only is printing the esc charcter on the screen. Still a novice and I can't find info on the ABS guide.

Code:
echo -e "This script is used to copy all the PKGBUILDS needed into a build 
directory of choice\n
This portion of print is a test" 

read key
 case $key in
	*) abscopy ;;
      255) leavin ;;
 esac

Its been awhile since I have been scripting... Though I can get the escape character to work with a dialog box...
 
Old 10-05-2009, 09:07 PM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by manwithaplan View Post
This is just an example... I would like it when I press "esc" "^]" to exit and run my leavin function. But it only is printing the esc charcter on the screen. Still a novice and I can't find info on the ABS guide.

Code:
echo -e "This script is used to copy all the PKGBUILDS needed into a build 
directory of choice\n
This portion of print is a test" 

read key
 case $key in
	*) abscopy ;;
      255) leavin ;;
 esac

Its been awhile since I have been scripting... Though I can get the escape character to work with a dialog box...
In order to read single characters, you would have to jump through hoops, and afterward you terminal session will be totally messed up.

Try to design your script so that it doesn't require responses to single keystrokes.
 
Old 10-05-2009, 09:13 PM   #3
manwithaplan
Member
 
Registered: Nov 2008
Location: ~/
Distribution: Arch || Sidux
Posts: 393

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by lutusp View Post
In order to read single characters, you would have to jump through hoops, and afterward you terminal session will be totally messed up.

Try to design your script so that it doesn't require responses to single keystrokes.
Thanks ... After spending more then hour on different escape sequences, your advice is sound... I adjusted my read with a -s switch and just going to go with a Ctrl-C.

Though if I could write a function that responded to characters on the keyboard would be nice... I might all together abandon this bash and use python.
 
Old 10-05-2009, 10:04 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,669

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
Its not to messy.

Code:
read -s -n1  key

 case $key in
     $'\e') echo "Escape";;
 esac
 
Old 10-05-2009, 10:18 PM   #5
manwithaplan
Member
 
Registered: Nov 2008
Location: ~/
Distribution: Arch || Sidux
Posts: 393

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by michaelk View Post
Its not to messy.

Code:
read -s -n1  key

 case $key in
     $'\e') echo "Escape";;
 esac
Ya I have tried this ... for some reason it always defaults to my "abscopy" function

Code:
clear
echo -e "This script is used to copy all the PKGBUILDS needed into a build 
directory of your coice\n
Press Enter to continue or Ctr-C to quit" 
read -s -n1 key
case $key in
	*) abscopy ;;
    $'\e') exit ;;   # I've specified my "leavin" function and even exit.
esac
So when I press the esc key it always continues the program with my "abscopy" function, even though its not specified in the case.
 
Old 10-05-2009, 10:23 PM   #6
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
You need your 'default' case at the end. Otherwise '*' will match before anything else is reached.
 
Old 10-05-2009, 10:33 PM   #7
manwithaplan
Member
 
Registered: Nov 2008
Location: ~/
Distribution: Arch || Sidux
Posts: 393

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by slakmagik View Post
You need your 'default' case at the end. Otherwise '*' will match before anything else is reached.
DOPE .... its been awhile ... forgot that there was a specific order...


Thanks
 
  


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
Pattern matching in a bash case statement using regex ciphyre Programming 1 01-31-2009 12:20 PM
bash case statement with multiple command line options pwc101 Programming 16 06-01-2007 11:43 AM
Pattern matching with a "case" statement in BASH King V Programming 8 04-27-2006 04:19 PM
Mapping Esc to windows key in Vim frankie_DJ Linux - Newbie 2 10-14-2004 02:56 PM
Damn 'Esc' key crabboy General 1 05-15-2001 10:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:22 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