Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Linux Tracker

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents
Up to --> Linux Tutorial

· Shells and Utilities
· The Shell
· The Search Path
· Directory Paths
· Shell Variables
· Permissions
· Regular Expressions and Metacharacters
· Quotes
· Pipes and Redirection
· Interpreting the Command
· Different Kinds of Shells
· Command Line Editing
· Functions
· Job Control
· Aliases
· A Few More Constructs
· The C-Shell
· Commonly Used Utilities
· Looking for Files
· Looking Through Files
· Basic Shell Scripting
· Managing Scripts
· Shell Odds and Ends

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Recommend Us
Surveys

Features
HOWTOs
News
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 249 guest(s) and 4 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  
Linux Tutorial - Shells and Utilities - Command Line Editing
  Different Kinds of Shells ---- Functions  


Command Line Editing

When I first started working in tech support, I was given a csh and once I figured out all it could do, I enjoyed using it. I found the editing to be cumbersome from time to time, but it was better than retyping everything.

One of my co-workers, Kamal (of IguanaCam fame), was an avid proponent of the Korn Shell. Every time he wanted to show me something on my terminal, he would grumble when he forgot that I wasn't using ksh. Many times he tried to convert me, but learning a new shell wasn't high on my list of priorities.

I often complained to Kamal how cumbersome vi was (at least I thought so at the time). One day I asked him for some pointers on vi, because every time I saw him do something in vi, it looked like magic. He agreed with the one condition that I at least try the ksh. All he wanted to do was to show me one thing and if after that I still wanted to use the csh, that was my own decision. Not that he would stop grumbling, just that it was my own choice.

The one thing that Kamal showed me convinced me of the errors of my ways. Within a week, I had requested the system administrator to change my login shell to ksh.

What was that one thing? Kamal showed me how to configure the ksh to edit previous commands using the same syntax as the vi editor. I felt like the csh editing mechanism was like using a sledge-hammer to pound in a nail. It does what you want, but it is more work than you need.

Many different shells have a history mechanism. The history mechanism of both the ksh and bash has two major advantages over that of the csh. First, the information is actually saved to a file. This is either defined by the HISTFILE environment variable before the shell is invoked, or it defaults to .bash_history (for the bash) in your home directory. At any point you can edit this file and make changes to what the ksh perceives as your command history.

This could be useful if you knew you were going to be issuing the same commands every time you logged in and you didn't want to create aliases or functions. If you copied a saved version of this file (or any other text file) and named it .sh_history, you would immediately have access to this new history. (Rewriting history? I shudder at the ramifications.)

The second advantage is the ability to edit directly any of the lines in your .bash_history file from the command line. If your EDITOR environment variable is set to vi or you use the set -o vi command, you can edit previous commands using many of the standard vi editing commands.

To enter edit mode, press Esc. You can now scroll through the lines of your history file using the vi movement keys (h-j-k-l). Once you have found the line you are looking for, you can use other vi commands to delete, add, change, or whatever you need. If you press "v," you are brought into the full-screen version of vi (which I found out by accident). For more details, check out the vi or ksh man-page or the later section on vi.

Note that by default, the line editing commands are similar to the emacs editor. If vi-mode is activated, you can activate emacs-mode with set -o emacs". Turning either off can be done with +o emacs or +o vi.

One exciting thing that bash can do is extend the command line editing. There are a large number of key combinations to which you can get bash to react. You say that the key combinations are "bound" to certain actions. The command you use is bind. To see what keys are currently bound, use bind -v. This is useful for finding out all the different editing commands to which you can bind keys.

 Previous Page
Different Kinds of Shells
  Back to Top
Table of Contents
Next Page 
Functions


MoreInfo

Test Your Knowledge

User Comments:


You can only add comments if you are logged in.

Copyright 2002-2009 by James Mohr. Licensed under modified GNU Free Documentation License (Portions of this material originally published by Prentice Hall, Pearson Education, Inc). See here for details. All rights reserved.
  




Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
You can get all the latest Site and Linux news by checking out our news page.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.08 Seconds