Operating System - HP-UX
1834302 Members
2666 Online
110066 Solutions
New Discussion

Arrow keys to browse history

 
Darren Gaile
Advisor

Arrow keys to browse history

Hi all,
I have now got a problem using the arrow keys to browse the history. Using the following in the .profile for each user works fine.

set -o emacs
alias __A="^P"
alias __B="^N"

However, if I place the following in the /etc/profile to be used for every user.

set -o emacs
alias __A="^P"

Nothing happens. If I place the following in the /etc/profile.

set - emacs
alias __A="^P"
alias __B="^B"

The arrow keys still don't browse the history but if I then try the alias command, the output from the console turns into garbage like the following.

__A=
__B=
jâ ¬`â  Â¡gΦΦΩδΠ⠩â e
â ©â eâ ¬`â  Â¡gΦΦΩδÎ

The prompt and any further output from the shell also show up as garbage. However, if I copy the garbage and paste it into another application in windows for example, the garbage turns into real text.

Everything works fine if I place these changes in the .profile for each user. It's only when I put it in /etc/profile that things
14 REPLIES 14
Victor Fridyev
Honored Contributor

Re: Arrow keys to browse history

Hi,

Look at the link
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=604661

HTH
Entities are not to be multiplied beyond necessity - RTFM
Darren Gaile
Advisor

Re: Arrow keys to browse history

Hi Victor,
That link describes placing the changes in each users ~/.profile. But I want each user to be able to use this facility without having to change each users .profile seperately. So I'm trying to put it in /etc/profile (the default profile). Things like prompts and other alias commands work fine in /etc/profile but the emacs features to browse the history won't work.
Darren Gaile
Advisor

Re: Arrow keys to browse history

Update!

I have discovered that placing set -o emacs in the etc/profile is the problem. It doesn't run there for some reason. If I have the

set -o emcas

in ~/.profile, I can have the

alias __A="^P"

in /etc/profile

Although this enables the browsing history with the arrow keys, it still displays the garbage when I execute the alias command at the shell prompt. And it still means changing ~/.profile for each user which I don't really want to do. Any ideas?
Bill Hassell
Honored Contributor

Re: Arrow keys to browse history

Look for TERM= in /etc/profile and in .profile. Shells critically depend on the TERM value being set correctly and hard coding TERM= will definitely cause problems. Replace any code (especially the /etc/profile code that tests for TERM already being set) that sets TERM to a constant with:

eval $(ttytype -s)

and remove any other TERM settings in .profile or other login steps. The weird characters may be caused by stty settings. The following is a good set for /etc/profile:

export TERM=$(ttytype -s)
stty erase "^H" kill "^U" intr "^C" eof "^D" -parity ixoff
stty susp \^Z dsusp \^Y
tput reset
tput rmln

As with all profiles, if you use batch software to start processes such as a database and the startup sequence uses su, be sure to protect all terminal commands from being executed in batch mode (where there is no associated tty device). Something like this:

if tty -s
then
...bunch of stty,tput,ttytype,tabs,etc commands
fi


Bill Hassell, sysadmin
Darren Gaile
Advisor

Re: Arrow keys to browse history

Have removed all TERM= in /etc/profile and .profile and left just the following in /etc/profile and this didn't work.

eval $(ttytype -s)

So the login process now has the following in /etc/profile and nothing related to this in .profile.

export TERM=$(ttytype -s)
stty erase "^H" kill "^U" intr "^C" eof "^D" -parity ixoff
stty susp \^Z dsusp \^Y
tput reset
tput rmln

.sh_history is still being written to but the arrow keys wont show the history and I'm still getting the strange characters after the entering the alias command.
Bill Hassell
Honored Contributor

Re: Arrow keys to browse history

The strange characters are most likely a feature of your terminal emulator. Start by identifying what codes the arrow keys actually transmit. There is a tput command to enable (smkx) and disable (rmkx) the transmission of the non-ASCII keys like arrows and home, page up/down, etc (man terminfo). You can use xd to show the codes:

tput smkx
cat | xd -cx

There won't be any prompts, just start typing and enter CTRL-D to exit. After CTRL-D, you'll see the codes that were transmitted. The strange characters look like ASCII characters with the 8th bit turned on. Check your terminal emulator manual to see how these codes are handled.

Are you using /usr/bin/sh (the POSIX shell)? bash has it's own list of possible profile files that may be doing some setups.


Bill Hassell, sysadmin
Darren Gaile
Advisor

Re: Arrow keys to browse history

The strange characters are the result of the emulator I'm using. Other emulators don't have the problem.

When I run xd and type the up arrow and enter followed by CTRL-D, I get.

0000000 1b4f 410a
1b O A \n
0000004


In terms of shells, root uses /sbin/sh while normal users use /usr/bin/sh.
Bill Hassell
Honored Contributor

Re: Arrow keys to browse history

The 1b O A means: ESC OA is transmitted by the arrow key. So the key does send a specific code. The terminfo (Curses) name for the up arrow is kcuu1 and by using untic and grepping for kcuu1, we see that:

untic vt100 | grep kuuc1
knp=\E[U, kpp=\E[V, kcuf1=\EOC, kcuu1=\EOA,

where \EOA is the until way of saying ESC OA will be expected from a vt100 terminal (o remulator) when the arrow key is pressed. What does ttytype -s say about your terminal? Programs (such as the POSIX shell which you are using) that use the Curses library will expect the value of TERM to match what the emulator does. If ttytype -s reports TERM=ansi then your emulator is flawed or misconfigured. An ANSI type terminal (untic ansi) will transmit ESC [A not ESC OA. You may have to give up on the emulator you're using if this is the case. There a LOT of terminal emulators out there, some of which appear to be written by programmers that may never have touched a 'real' terminal or know much about terminal codes and responses.


Bill Hassell, sysadmin
Darren Gaile
Advisor

Re: Arrow keys to browse history

Having the following

set -o emacs
alias __A="^P"

in ~/.profile works fine for that particular user. It's only if I try to do this in /etc/profile that I get a problem and this is what I don't understand. If my emulator was faulty, I wouldn't expect it to work either way.

ttytype -s gives:

TERM='vt320'; export TERM;
LINES=24; export LINES;
COLUMNS=80; export COLUMNS;
ERASE='^?'; export ERASE;

Oh, and I only get garbage after typing alias at the prompt if I have

alias __B="^N" in /etc/profile
Joe Bozen
Advisor

Re: Arrow keys to browse history

Hi everyone,

I too am attempting to get my arrow keys working. I found a lot of ideas from this listserv.

I edited my .profile file and added

alias __B="^P"

however, my down arrow key now prints ^P and not the actual escape sequence of CTRL-P. What do I need to enter in my .profile for ^P to make my system work.

key-less in Chicago
Joe Bozen
Advisor

Re: Arrow keys to browse history

Ok,

It's working...

Here is what I used:

alias -x __A="$(echo '\020')" # Ctrl-P: Line up (Previous)
alias -x __B="$(echo '\016')" # Ctrl-N: Line down (Next)
alias -x __C="$(echo '\006')" # Ctrl-F: Character right (Forward)
alias -x __D="$(echo '\002')" # Ctrl-B: Character left (Backward)

joe...
Victor_95
Occasional Advisor

Re: Arrow keys to browse history

__A
__B
__C
__D
Where can I find this codes to any ather key
(Delete, Insert, Home, End, PageUp, PageDown, etc.)
Joe Bozen
Advisor

Re: Arrow keys to browse history

I used some documentation on the vi editor to determine what ctrl-keys controled cursor movement.

joe...
selcuk_1
Advisor

Re: Arrow keys to browse history

Hey,

here needs an update ...

Just the people above, I have managed to map arrow keys and command history with

alias -x blah blah..

but when I want this setting to be common for everyone, I had to put it in /etc/profile.. And of course it didn't work (here is unix world ..!)

So as stated above, the problem was with "set -o emacs". SOmehow it conflicts with the user .profile's last lines

# Set up the shell variables:
EDITOR=vi
export EDITOR

when I delete those lines. set-o emacs line in /etc/profile has worked !

By the way, I suggest to remove these lines from /etc/skel/.profile (for ksh)

so that new users can be crated without problems..



search for the meaning