Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubt in history command

Status
Not open for further replies.

sureshp

Programmer
Aug 28, 2000
79
0
0
If I want to change some thing in the previous comman through r command like

I typed histori instead of history

# histori
histori not found

Then I am typing

#r i=y
hystori not foung

This is what I am getting, r replaces only the first ocurence of the letter. How can I change the second and forth on.
Suresh
 
hi

i dunnno if this is what u want... but my bet is on
#!!s/ri/ry/

i use the csh.. but the point is still clear i hope..

afaik,
shail
 
Hi, your idea is good . But I am not at all able to execute the history commands through !! or !n where n is a command number in history file.
What Can I do, if I want to execute the last command as !!
I am workin in Ksh, SCO Unix. I am comfortable with r script
which is also used for executing history commands.

regards

Suresh
 
Hi, your idea is good . But I am not at all able to execute the history commands through !! or !n where n is a command number in history file.
What Can I do, if I want to execute the last command as !!
I am workin in Ksh, SCO Unix. I am comfortable with r script
which is also used for executing history commands.

regards

Suresh
 
hi suresh,

if u r comfortable with vi try &quot;ksh -o vi&quot;. here the command line interface is vi editor. hence u can recall the earlier commands with <escape>k .. i mean command mode , edit mode etc.


csh provides builtin history and earlier command processing... for ksh man page suggests command fc:-(

afaik,
shail
 
ok -- so you make a mistake on the command line in ksh

type ESC
type -
press the space bar until you get to your mistake on the line
use vi editing commands to correct it
press ENTER

If you don't know vi then have a look at
 
A couple of things:

To change &quot;histori&quot; to &quot;history&quot;, skipping the first &quot;i&quot;, you need to make the change pattern more unique. Here's a transcript from a shell session to illustrate:
[tt]
315 (root) /etc/mail > r ri=ry
history 300 kill -9 26237
301 ps -efa|grep sendmail
302 cd /
303 ls -l dead.letter
304 df -k .
305 clear;exit
306 sar 3 3
307 sar 5 5
308 sar 3 3
309 sar 3 3
310 cd /etc/mail
311 who
312 sar 3 3
313 ps
314 histori
315 history
316 (root) /etc/mail >
[/tt]
(BTW, I don't usually work as root, I just happened to be multi-tasking while scanning Tek-Tips ;^)

The &quot;!!&quot; mechanism isn't available in the korn shell. &quot;!!&quot; is csh's equivalent to the ksh &quot;r&quot; command. You may be able to alias &quot;!!&quot; so that it runs &quot;r&quot;, but it would probably be better in the long run to learn how &quot;r&quot; works.

Finally, an easy way to make your default command line edit mode be set to &quot;vi&quot; is to set the EDITOR environment variable to be &quot;vi&quot;.

Hope this helps.
 
hi again,

adding on that fc is the process command history list.
in korn r is mapped to fc -e - . (man fc makes interesting reading)


now is there a way to trap the up arrow key press and down arrow key press and then map it to print the earlier command on the screen??

-regds,
shail
 
now is there a way to trap the up arrow key press and down arrow key press and then map it to print the earlier command on the screen??

I was never able to do this in the Korn shell, so I downloaded the source for Bash (Bourne Again SHell) instead. Think of Bash as being Korn shell with knobs on, one of which is the use of the GNU readline library to use the cursor keys to manipulate the command line.

As well as the standard .profile (or .bashrc) start up file, you can also have a .inputrc that lets you remap your keyboard events.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top