Using history and command line editing

on this topic
September 28, 2001, 01:55 PM —  Unix Insider — 

One
of the great features of the C shell and the Korn shell is history.
The ability to recall and reuse commands that you have entered earlier
can save many keystrokes of repetitive typing. History and command line
editing are closely related. You may use command line editing to
edit the command that you are currently working on after you have typed
it in, or you may recall a previous command and then edit it.

In this article, I will show you some of the ins and outs of
history and command line editing in the Korn shell. For history to
work, you need to be in the Korn shell, so begin by typing:


ksh

to launch a Korn shell.

The second thing you need to make history work is an easy way to
access it. History is more than just the ability to recall
previous commands; it lets you recall commands and edit them before they are
executed. The Korn shell allows you to use different editing styles
depending on what you're trying to do. The primary
editors are vi, emacs, and gmacs. I recommend vi, as most people are
familiar with it. History and command line editing behave very
differently depending on whether you are using vi, emacs, or gmacs. I
will cover some of these differences.

To set vi up as your history editor type:


set -o vi

If you are going to continue to use history, you will want to include
this in your profile, or the emacs/gmacs equivalents. These set -o
commands only work in the Korn shell:


set -o emacs
or
set -o gmacs

Assuming that you have set -o vi as your history editor,
you may now access history. Press the escape key once (esc) and
release it and press k. The last command that you typed will
appear on the screen:


$ set -o vi

Press enter and that command will be executed. Try a few more
commands so that you can accumulate some history. End with ls
-l
on the current directory. Now press esc
and k. The ls -l command appears once more. Press k again and
the command just prior to ls -l will appear. Each time you press k
you'll go back one more command in your history. The minus key ( - )
works in exactly the same way. I use the minus key because it's easier for me
to remember. Eventually, if you press k or minus enough times, you'll
end up back at the set -o vi command.

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

jfruh
Apple syncing patent can't come soon enough

pasmith
New Twitter features borrow from 3rd party clients

Esther Schindler
Open Source Changes the Software Acquisition Process

mikelgan
How to set up continuous podcast play on the new iTunes

David Strom
Five important Windows 7 mobility features

sjvn
Guard your Wi-Fi for your own sake                        

Sandra Henry-Stocker
Grepping on Whole Words

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace