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

Enterprise 2.0 Implementation
By Aaron C. Newman, Jeremy Thomas
Published by McGraw-Hill
Learn more!

Deploying Cisco Wide Area Application Services
By Zach Seils, Joel Christner
Published by Cisco Press
Learn more!

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.

More Resources