1759410 Members
3224 Online
108882 Solutions
New Discussion юеВ

command history recall

 
Chris Conrad
Occasional Advisor

command history recall

I am trying to set up command history recall on my HP C3600 Worstations. When I type K to recall the previous command, all I see on the screen is ^[K. What do I need to set up to capture the ?
9 REPLIES 9
Stefan Farrelly
Honored Contributor

Re: command history recall

Normally its ESCAPE-k to recally your command. As long as your have HISTFILE set up and a set -o vi command done (in your .profile) then ESC-k should work fine.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Armin Feller
Honored Contributor

Re: command history recall

If history function is configured, [ESC] [k] will recall the commands.

To configure history function, please do following:

# vi .profile
...
HISTSIZE=500
HISTFILE=.sh_history
export HISTSIZE HISTFILE
EDITOR=vi
export EDITOR

# touch $HOME/.sh_history

After re-read the .profile you should be able to get the history function.
Chris Conrad
Occasional Advisor

Re: command history recall

there must be something you have to set up in the terminal settings to capture the escape key before it goes to the screen, because it just shows up as ^[k
Steve Labar
Valued Contributor

Re: command history recall

Your HISTFILE should be setup as
HISTFILE=${HOME}/.sh_history
Then make sure the file is created
touch ${HOME}/.sh_history

Keep in mind, this history recall is for sh and ksh only. If you are using csh, you recall history using '!'.

Good Luck.

Steve
Francisco J. Soler
Honored Contributor

Re: command history recall

Hi, if your terminal is not well configured you could try with the c-shell, type in
csh
and then yo can view the history with the history command.
To repeat the last command just type !!, and to repeat another one just type !n, when n is the number showed in the history command.

Frank.
Linux?. Yes, of course.
K.Vijayaragavan.
Respected Contributor

Re: command history recall

"ksh -io vi" command allows you recalling commands and altering using vi commands.
You may put the same in profile.

-Vijay
"Let us fine tune our knowledge together"
V. Nyga
Honored Contributor

Re: command history recall

Hi Chris,

check your login shell
'env|grep SHELL'

If you have csh it will work like Francisco told, if you have ksh it should work like discribed above.

Volkmar
*** Say 'Thanks' with Kudos ***
Martin Johnson
Honored Contributor

Re: command history recall

You may have to set the variable:

EDITOR=vi; export EDITOR

also, make sure you are the owner of the .sh_history file and read/write permissions are set for the owner.

HTH
Marty
Brian M Rawlings
Honored Contributor

Re: command history recall

Stephen mentioned adding a line to your .profile; no one else has mentioned it, but I have found it to be needed:

set -o vi

I'm not sure quite what the interaction is between setting the EDITOR=vi variable, and using the 'set -o vi' command, I have both in my .profile (too superstitious to leave either out). But, as I recall, the 'set' command was what did the trick to get to bring back history of commands. Plus all the other things that have been mentioned (like, you have to set the HIST... variables, and the history file you set in a variable has to exist).

One point about the sequence, once you get vi correctly set up as your line editor: once you hit , you are in 'vi edit mode'. So, if you realize you left a word out of a long command, you hit , and then use the 'h' key (cursor left, in vi) to move back to that spot, then hit 'i' to enter insert mode, add what you need, and then enter the whole command line with a .

Other vi functions work when you are in 'vi mode', such as a '/' to search back through your command history, rather than just going back sequentially, etc. All your favorite 'vi' functions, like 'cw' to change a word, or 'dw' to delete a word, can be used once you hit .

I couldn't live without it, and it is one of the first things I get set up, when I have to work on a unix system that doesn't do this... which poses a bit of a problem on Solaris, or Linux, where setting this up is different.

Hope it helps... --bmr
We must indeed all hang together, or, most assuredly, we shall all hang separately. (Benjamin Franklin)