• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1182
  • Last Modified:

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.

Thanks!
0
rainbowhi
Asked:
rainbowhi
  • 5
  • 3
  • 2
2 Solutions
 
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.


Kent
0
 
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.
0
 
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...


Kent
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

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

Have a nice day!
0
 
woolmilkporcCommented:
Basically,
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.

wmp


0
 
rainbowhiAuthor Commented:
Hi,
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
fi

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

ulimit -d unlimited

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

Thanks!
0
 
woolmilkporcCommented:
OK,

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?

wmp
0
 
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:
--------------------------------------------------------------------------------------------------------------
__A=
__B=
__C=
__D=
__H=
__P=
autoload='typeset -fu'
cdbin='cd /$HOME;pwd'
cls=clear
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'
local=typeset
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 ksh.cat SUSPEND "suspend: cannot suspend login shell
"; fi '
type='whence -v'
vi=/usr/bin/vi
----------------------------------------------------------------------------------------------------------------------
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.
0
 
woolmilkporcCommented:
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 .
wmp
 
0
 
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.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now