Use up-arrow key to retrieve the previous commands

Hi, I want to know how to get it working so I can use the up-arrow key to retrieve the previous commands. It is working fine on one of my AIX servers, but doesn't work on my new server.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenData Warehouse Architect / DBACommented:
Hi rainbowhi,

It depends on what shell you're using, and to some extent what editor is set as the default.

Check the user on the old system and make sure that you're using the same shell, probably bash.

You're probably using the korn shell (ksh) on the new system.  If the default editor is vi, ESC-K will get you that last command, and ESC-K and ESC-J will cycle up and down.

rainbowhiAuthor Commented:
Hi Kdo,
Thanks for your response. I think both of my systems are using ksh, because echo $SHELL returned: /usr/bin/ksh.
I did put set -o vi in the new system and the ESC-K and ESC-J works, but the up-arrow doesn't work.
I checked on the old system, the set -o-vi was commented out: #set -o vi, but both ESC-K,J and up-arrow work. So I'm confused.
Kent OlsenData Warehouse Architect / DBACommented:
Hi rainbowhi,

The devil's always in the details.  :)

It has been years since I configured the arrow keys on an AIX system so I'm having to steer you to what to check.  (Apologies.....)

I suspect that you're using the emacs editor on the "old" system.  There may also be a difference in the terminal type, key mapping, etc.  Just changing the editor probably isn't sufficient to get the arrow keys working, but you can try it.

  set -o emacs

If that doesn't work, log out and back in to reset the variables to the baseline.  Then:

-- Check the file /etc/environment on both systems to see if a different default is being used.  
-- If that doesn't lend a clue, check /etc/profile.
-- If there's still no answer, compare the output from the set, env, and alias commands (with no parameters).

Somewhere in all that should lie the solution...

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

rainbowhiAuthor Commented:
Thanks, Kent!
I will try it tomorrow in the office and let you know.

Have a nice day!
if you actually use emacs-style command line editing, you need to have the following aliases defined:

alias __A=$(echo "\020")   # up arrow = ^palias __B=$(echo "\016")   # down arrow = ^nalias __C=$(echo "\006")   # right arrow = ^falias __D=$(echo "\002")   # left arrow = ^b
Set these aliases in /etc/profile or your personal .profile. Don't forget to add

set -o emacs

to the respective file, and to logout and re-login.


rainbowhiAuthor Commented:
I don't have access to the new server for a few days, and didn't test yet.
But anyway, here is what I got from the profile on my old server where up arrow works fine:
alias l="clear;echo;echo;ls -la `$1` | more;echo;echo"
alias lrt="clear;echo;echo;ls -la -t | more;echo;echo"
alias m="more `$1`"
alias dir="clear;echo;ls -la;echo;echo"
alias dird="clear;echo;ls -la | grep ^d;echo;echo"
alias cls="clear"
alias dirln="clear;echo;echo;ls -lg | grep ^l;echo;echo"
alias dirf="clear;echo;echo;ls -la | grep ^-;echo;echo"
alias dirp="clear;echo;echo;ls -la | more;echo;echo"
alias env="env | more"
alias installed="lslpp -al | more"
alias cdbin="cd $HOME/bin;pwd"

## If TERM is "ANSI", then change to "vt100".
if [ $TERM = "ANSI" ]; then
    export TERM=vt100

# Please DO NOT include PWD in the prompt.
export PS1="\[SERVERNAME\] \${PWD}> "
export TERM=vt100
export VISUAL=emacs
export EDITOR=/usr/bin/vi
. $HOME/.cursors

ulimit -d unlimited

#:set -o vi
I am not sure what we are using. Need some advise.


let's put it together.

1) Don't use "echo $SHELL" to check for your login shell. Rather use "echo $0" instead (the minus in front of the displayed string means "login shell").

2) If you use ksh as your login shell and want to use the up arrow, you need

- the aliases I mentioned in my previous post

- "set -o emacs" or "export VISUAL=emacs".
These two are somewhat equivalent, the moment you issue "export VISUAL=emacs" the shell issues "set -o emacs" for you.

This means that if you issue "set -o vi" after "export VISUAL=emacs" the last issued setting takes effect (vi) and you will not have "up arrow" support, regardless of the alias settings.

3) If you use bash as your login shell (you need to install it separately from the toolbox) you must issue

- "set -o emacs" or "set -o vi" to use the up arrrow. No aliases are needed.
The VISUAL setting has no effect on this, unlike with ksh.

I'm not aware how to bind the arrow keys when using "set -o vi" in ksh under AIX.
I heard that this was possible with other UNIXes though and would be very glad to learn how to make it possible, but I doubt that there will be a way.

So I assume that you either use bash on your working server or that the aliases are being set somewhere.

What does a simple "alias" command (without parameters) say?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rainbowhiAuthor Commented:
Hi wmp,
Thank you so much for the explanation!
I think I am using ksh. Here is what's returned when I entered alias without other parameters:
autoload='typeset -fu'
cdbin='cd /$HOME;pwd'
command='command '
dir='clear;echo;ls -la;echo;echo'
dird='clear;echo;ls -la | grep ^d;echo;echo'
dirf='clear;echo;echo;ls -la | grep ^-;echo;echo'
dirln='clear;echo;echo;ls -lg | grep ^l;echo;echo'
dirp='clear;echo;echo;ls -la | more;echo;echo'
env='env | more'
functions='typeset -f'
hash='alias -t -'
history='fc -l'
installed='lslpp -al | more'
integer='typeset -i'
l='clear;echo;echo;ls -la  | more;echo;echo'
lrt='clear;echo;echo;ls -la -t | more;echo;echo'
m='more '
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='if [[ ${0#-} = $0 ]] ; then kill -STOP $$; else dspmsg -s 1 SUSPEND "suspend: cannot suspend login shell
"; fi '
type='whence -v'
But one thing I am not clear, the old server doesn't have the lollowing alias defined:
alias __A=$(echo "\020")   # up arrow = ^p
alias __B=$(echo "\016")   # down arrow = ^n
alias __C=$(echo "\006")   # right arrow = ^f
alias __D=$(echo "\002")   # left arrow = ^b

How is it working?

Sorry for so many questions.
As I wrote - I'm not aware at all how to make the key bindings work under AIX/ksh without defining the aliases and using emacs.
There is a ksh93 in AIX which does provide support for the key bindings (without setting aliases) for the emacs and vi modes.
This shell is called /usr/bin/ksh93, however.
"echo $SHELL" would give  "/usr/bin/ksh93", "echo $0" would give "-ksh93".
Of course it could be that your old server has /usr/bin/ksh linked to /usr/bin/ksh93. This is not recommended by IBM, because some internal scripts could run into problems with ksh93.
I never tried it, but I guess it will work nonetheless. Please be aware that an OS update (TL, ServicePack) can (and probably will) overwrite the link with a "real" ksh .
rainbowhiAuthor Commented:
Thank you so much for the explanation! I don't think ksh93 is used in the old server or there is a link to it.
 I still don't have access to the new server yet, but will definitely try it on Monday.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.