topics that matter; ideas worth sharing

share a tip, submit a link, add something new

Getting the most from your shell

March 29, 2001, 05:46 PM —  Unix Insider — 


While the rest of the world points and clicks in a world of icons, we in the world of Unix get to use a good old-fashioned command-line interface (CLI). One reason the command line has remained so pervasive in Unix environments is that its implementation -- the Unix shell in its various incarnations -- is very good. With it, the user can build new tools with the ones provided.


To keep things simple, I'll talk about three shells in particular, all in the Bourne shell tradition: /bin/sh, /bin/ksh, and /bin/bash. I'll try to focus on features that all three share, though inevitably I'll have to discuss features that the older shell doesn't have, notably job control and command-line editing.


Command-line editing



The first way to make the shell easier to use is to set up command-line editing. Two types are commonly available in shells derived from the Korn shell: those using the vi commands, and those using Emacs editing keystrokes. They are very different, and users who swear by one will take pains to avoid the other.


In both ksh and bash, to activate vi command-line editing, type:


set -o vi


This allows you to use the same set of command keys you have available in vi.


In both ksh and bash, to activate Emacs command-line editing, type:


set -o emacs


This allows you to use a subset of Emacs command keys, and treat the command line as a sort of one-line Emacs buffer.


Shell options



Setting which type of command-line editing you prefer is just one instance of setting the shell options that control many aspects of your shell's behavior. You set shell options using set -o. Options can be unset using set +o.


The man page for your shell will list all the options; here, I'll focus on a few that I think you'll find useful.

  • notify: Prints job-notification messages asynchronously, instead of just before the prompt. Both ksh and bash support this option.
  • noclobber: In both ksh and bash, this prevents > redirection from overwriting existing files. With this set, >| must be used to force an overwrite, or else the shell will tell you cannot create [file]: File exists.
  • bgnice: Runs background jobs with lower priority. This is in ksh, but not in bash.
  • ignoreeof: Determines that shell will not exit on end-of-file (^D); exit must be typed. To avoid infinite loops, pdksh will exit if EOF is read 13 times in a row. The implementation in bash is more sophisticated. To quote the man page:


    "If set, the value is the number of consecutive EOF characters typed before bash exits. If the variable exists but does not have a numeric value, or has no value, the default value is 10. If it does not exist, EOF signifies the end of input to

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.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff
Featured Sponsor

Get a broad understanding of important regulations and how you can make sure your site is in adherence.





Learn how VeriSign SGC-enabled SSL Certificates can help improve site security and customer confidence in the free white paper, "How to Offer the Strongest SSL Encryption." In this paper you will learn the differences between weak and strong encryption and what they mean for your site's performance.

Get VeriSign's free white paper: "The Latest Advancements in SSL Technology" and learn about the benefits of strong SSL encryption, Extended Validation (EV) SSL and security trust marks and what these SSL offerings can do for your site.

Now with Extended Validation (EV) SSL available from VeriSign, you can show your customers that they can trust your site. Learn about EV SSL benefits in this free VeriSign white paper.

More Resources