LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 08-12-2010, 07:37 AM   #1
rob_L
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Rep: Reputation: 0
Bash: echo the arrow keys


Is it possible to echo the arrow keys (up, down, left, right) in bash?
I know echo -e \033 echos escape but what about arrows?

Thank you.
 
Old 08-12-2010, 11:07 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
ANSI Escape sequences may be what you are looking for.
 
Old 08-12-2010, 11:21 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
you might find these variables helpful
Code:
KEYS_ESC=$'\e'
KEYS_F1=$'\e'[[A
KEYS_F2=$'\e'[[B
KEYS_F3=$'\e'[[C
KEYS_F4=$'\e'[[D
KEYS_F5=$'\e'[[E
KEYS_F6=$'\e'[17~
KEYS_F7=$'\e'[18~
KEYS_F8=$'\e'[19~
KEYS_F9=$'\e'[20~
KEYS_F10=$'\e'[21~
KEYS_F11=$'\e'[22~
KEYS_F12=$'\e'[23~
KEYS_HOME=$'\e'[1~
KEYS_HOME2=$'\e'[H
KEYS_INSERT=$'\e'[2~
KEYS_DELETE=$'\e'[3~
KEYS_END=$'\e'[4~
KEYS_END2=$'\e'[F
KEYS_PAGEUP=$'\e'[5~
KEYS_PAGEDOWN=$'\e'[6~
KEYS_UP=$'\e'[A
KEYS_DOWN=$'\e'[B
KEYS_RIGHT=$'\e'[C
KEYS_LEFT=$'\e'[D
KEYS_NUMPADUNKNOWN=$'\e'[G
 
Old 08-12-2010, 08:03 PM   #4
rob_L
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks all.

Konsolebox: how do I echo them? for example would echoing an arrow down be;
echo -en $'\e'[B
 
Old 08-12-2010, 08:19 PM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Those values do not represent a character. They merely are the generated sequence of characters when you press a special key on a terminal. For example if you cast read on a terminal like this:
Code:
read -t 1 REPLY
Once you press a key you'll notice that the output will be something like '<escape char>[B'.
If you echo the value of REPLY, the output will just be the same:
Code:
echo -n "$REPLY"
You'll find that it will just be similar to the echo you're after:
Code:
echo -n $'\e'\[B
If you really want to produce the up or down arrow character you should do this:
Code:
echo -n $'\030'  # up arrow key
echo -n $'\031'  # down arrow key
The characters that are shown might also depend on the terminal you have.

Reference: http://classicteck.com/maxdev/ascii.html

Last edited by konsolebox; 08-12-2010 at 08:29 PM.
 
  


Reply



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
Bash case with arrow keys (and DEL, BACKSPACE,etc) sadarax Programming 11 02-15-2012 11:15 AM
Arrow keys not working flamingvan Solaris / OpenSolaris 5 10-03-2006 05:47 AM
Shift-arrow and Alt-arrow keys don't work in xterm Aviv Hurvitz Linux - General 2 09-30-2006 03:43 PM
VIM and the arrow keys Buto Linux - Software 1 09-16-2004 07:38 PM
Arrow keys in nethack Levitate Linux - Games 3 08-22-2004 11:44 AM

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

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