This article describes common functionality that is often thought lacking in ksh but is just hiding in unintuitive corners (such as command line completion!)

My preferred shell is bash but I often find myself on ksh because it is the default shell on Sun boxes. It has always drove me insane trying to remember how to accomplish very simple things like scrolling through history in ksh. Hopefully by writing it down I will remember or at the very least have a place to go look it up without searching google.

Command Scrolling

Command scrolling is the trick whereby you can scroll through previously typed commands in your shell history. In bash this is a simple matter of using the arrow keys. Unfortunately, ksh is not so intuitive.

Note that the following are based on vi mode editing. Thus, the following command must be in your .profile to work:

export VISUAL=vi

If you wish to use emacs commands for editing then you are on your own

  1. Press the Esc key
  2. Press k to scroll back through the history list
  3. Press j to scroll forward through the history list

Command Editing

Editing the command line is identical to using command scrolling and without going through every vi command possible here are some basics:

  • h = scroll left
  • l = scroll right
  • ^ = move to beginning of line
  • $ = move to end of line
  • i = insert
  • a = append
  • x = delete
  • dw = delete word
  • cw = change word

Command Line Completion

The command line can be much faster than a GUI interface if you know what you are doing and one of the greatest productivity boosters is command line completion. Most decent shells provide a way of doing predictive completion on commands, filenames, and pathnames. In the bash shell this is accomplished by hitting the Tab key and the shell will complete the word you are typing to the best of its ability. In ksh command line completion is accomplished by doing the following:

  • Press the Esc key
  • Press the \
  • Press the - to see a list of all possible completions

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 rootsmith blog Suffusion theme by Sayontan Sinha