Operating System - HP-UX
1829829 Members
2007 Online
109993 Solutions
New Discussion

Re: How to Set up history mechanism for command recall editing

 
SOLVED
Go to solution
wangmx
Respected Contributor

How to Set up history mechanism for command recall editing

hi,
In HP-UX11i OE,how to Set up history mechanism for command recall editing for users.

Thanks
12 REPLIES 12
Barry Sollitt
Advisor
Solution

Re: How to Set up history mechanism for command recall editing

Put this is the users profile;

# Set up logging
HISTFILE=${HOME}/.sh_history_`who am i|awk {'print $1'}`
date >> $HISTFILE
export HISTFILE
HISTSIZE=500
export HISTSIZE

This will keep a shell history for command recall.

In /usr/bin/sh ESC K will recall.
"I'm the Man"
Naveej.K.A
Honored Contributor

Re: How to Set up history mechanism for command recall editing

hi,

put HISTFILE=.sh_history in .profile of the $HOME of the user

with best wishes
naveej
practice makes a man perfect!!!
Anupam Anshu_1
Valued Contributor

Re: How to Set up history mechanism for command recall editing

In .profile file in home directory, add the following line (you can add this line at the end of the .profile file).

----------------------------------------
export HISTFILE=/tmp/$LOGNAME.sh_history
----------------------------------------
After adding this line either re-login or execute your . profile. You can execute your .profile as follows:
---------------------------
$ . ~/.profile
$
---------------------------

The histfile would be created in /tmp directory.

Regards,

Anshu
Robert-Jan Goossens
Honored Contributor

Re: How to Set up history mechanism for command recall editing

Hi,

add on to above messages,

EDITOR=vi
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
HISTSIZE=1000
EXPORT EDITOR HISTFILE HISTSIZE

regards,
Robert-Jan
wangmx
Respected Contributor

Re: How to Set up history mechanism for command recall editing

Can I use UP or DOWN key to recall commands?
Barry Sollitt
Advisor

Re: How to Set up history mechanism for command recall editing

No mate.

ESC K will recall the last command.
"I'm the Man"
Jeroen Peereboom
Honored Contributor

Re: How to Set up history mechanism for command recall editing

L.S.

Besides defining $HISTFILE and $HISTSIZE (that controls how many commands are saved) you can also choose the desired editor by defining $EDITOR EDITOR=vi or EDITOR=emacs.

Some people define a HISTFILE per login session such that simultaneous session do not share the history file (by using the proces id ($$) in the line HISTFILE=.sh_history_$$
Each time you login you start with an empty history.

Of course this leads to the problem that once in a while you must remove old history files (or remove the file on logout).

Check the shell's man page and search for HISTFILE and so on.

JP.
Anupam Anshu_1
Valued Contributor

Re: How to Set up history mechanism for command recall editing

Wanted to add one more point.

If you are not able to recall your messages by using either escape-k or escape-'-' (excape minus), then you do following:

$ set -o vi
$ escape-k

Regards
Jan Sladky
Trusted Contributor

Re: How to Set up history mechanism for command recall editing

hi,
the simpliest way is this:

into $HOME/.profile put the following row:

export HISTFILE=~/sh_history

to be able to repeated commands you also would have this row in the same file:

set -o vi

and repeating is done like in vi via ESC (command mode) and than k

hope this will help you
br Jan
GSM, Intelligent Networks, UNIX
Dani Seely
Valued Contributor

Re: How to Set up history mechanism for command recall editing

Here's a way that any user can control their history setup ...

If a user is not using the korn shell, they can switch to the korn shell so history will be retained by doing the following:

$ exec ksh
$ set -o vi

Now, to go back through their history of commands they would simply do:

$ k

This will take them through their previous commands from recent to oldest, and they can use the vi movements to move through the line and change previous commands.
Together We Stand!
Dani Seely
Valued Contributor

Re: How to Set up history mechanism for command recall editing

Note: The user would have to execute this again if they are not assigned the korn shell as their login shell and they logout:

$ exec ksh
$ set -o vi
Together We Stand!
Victor Fridyev
Honored Contributor

Re: How to Set up history mechanism for command recall editing

Hi,

After setting history you have two options for command editing: vi and emacs. They can be set by
set -o vi
or
set -o emacs in .kshrc file.
vi is more powerful: in addition to ESC-k, ESC-j, ESC-h and ESC-l (moving up,down,right and left) you can find a pattern in history by ESC-/ and edit found command using vi commands (delete. replace etc). But if you prefer simplicity of emacs, you also may use this option with CTRL-P (previous), CTRL-N (next) and to move left and right by appropriate arrows.

HTH
Entities are not to be multiplied beyond necessity - RTFM