LINUX TIPS AND TRICKS --- December 01, 2000

Published by ITworld.com, the IT problem-solving network
http://www.itworld.com/newsletters

--------------------------------------------------------------------------------

Command Shell Options
By Danny Kalev

This week I will explain how to toggle specific features to control the
way BASH executes certain commands.

The 'set' command turns features on and off. It takes two arguments: a
flag indicating whether a feature is turned on or off, and the feature
itself. The first argument has two forms: -o and +o which indicate off
and on, respectively. For example, to avoid exiting from an active shell
due to an extra CTL-D keypress, you can turn the 'ignoreeof' feature as
follows:

  $ set +o ignoreeof

From now on, pressing Ctl-D doesn't log the user out of the command
shell. What is it good for? As you probably know, Ctl-D is used for
logging out of a shell but it also indicates the end of an input stream
in many utilities. For example, the 'cat' utility treats Ctl-D as an end
of a user's input. When using 'cat' or similar applications, you may
inadvertently log yourself out of the command shell by entering an extra
Ctl-D. Turning on the ignoreeof feature causes the shell to ignore
redundant Ctl-D keypresses. In this case, you should use the 'logout'
command to logout.

Noclobber
The noclobber feature protects existing files from being overwritten
accidentally by redirected output. Suppose you decide to redirect the
standard output to a file. If the output filename is identical to an
existing filename, the system will overwrite the latter. To avoid this,
activate the noclobber option before redirecting output:

  $ set +o noclobber
  $ cat vocabulary > mylist
    mylist: file exists
  $

Note that you can override the noclobber option without having to turn
it off. This is useful when you want to redirect output to an existing
file, thereby overwriting it deliberately. To do so, place an
exclamation point after the redirection sign:

  $ set +o noclobber
  $ cat vocabulary >! mylist

Noglob
Setting the noglob feature disables special characters in the user
input. Thus, instead of letting the shell process these special
characters, they are treated as ordinary characters. Turning on the
noglob feature is useful when you have files whose names contain special
characters such as *, ?, ~, &#91;, &#93;, and ?. To list a file called
inventory* with the 'ls' command, first turn on the noglob feature:

  $ set +o noglob

Now list it:

  $ ls  inventory*
   inventory* 

Without noclobber turned on, the above 'ls' command would display all
the files in the current directory whose names begin with inventory.


About the author(s)
----------------
Danny Kalev is a system analyst and software engineer with more than 10 
years of experience, specializing in C++ and object-oriented analysis 
and design on various platforms including VMS, DOS, Windows, Unix, and 
Linux. His technical interests involve code optimization, networking, 
and distributed computing. He is also a member of the ANSI C++ 
standardization committee and the author of ANSI/ISO C++ Professional 
Programmer's Handbook (Que, 1999). Contact him at linuxnl@excite.com. 

--------------------------------------------------------------------------------

ADDITIONAL RESOURCES

Getting the most from your shell 
A helpful guide to command-line editing, aliases and functions, and 
shell programming 
http://www.itworld.com/jsw/lintps_nl/swol-10-2000/swol-1027-unixshell.html

Tips on good shell programming practices 
What #! really does 
http://www.itworld.com/jsw/lintps_nl/swol-09-1999/swol-09-unix101.html

Quick lessons on shell programming 
How to start writing your own shell scripts 
http://www.itworld.com/jsw/lintps_nl/swol-09-1997/swol-09-unix101.html

The language of shells 
Making sense of shell commands 
http://www.itworld.com/jsw/lintps_nl/swol-07-2000/swol-0728-unix101.html

--------------------------------------------------------------------------------

COMMUNITY DISCUSSIONS

Linux Software Development
Hone your Linux development skills, share your expertise, and put out 
the occasional call for help in this discussion for programmers of all 
levels. Moderated by Danny Kalev. 
http://www.itworld.com/jump/lintps_nl/forums.itworld.com/webx?14@@.ee6b652/198!skip=138

Troubleshooting Unix
Ask questions, offer solutions, and tell your tales in this lively 
discussion of the good, bad, and ugly sides of managing Unix systems. 
http://www.itworld.com/jump/lintps_nl/forums.itworld.com/webx?14@@.ee6b677

--------------------------------------------------------------------------------

CONTACTS

* For editorial comments, write Andrew Santosusso, Associate Editor, 
  Newsletters at: andrew_santosusso@itworld.com

* For advertising information, write Dan Chupka, Account Executive at:
  dan_chupka@itworld.com

* For recruitment advertising information, write Jamie Swartz, Eastern
  Regional Sales Manager at: jamie_swartz@itworld.com or Paul Duthie,
  Western Regional Sales Manager at: paul_duthie@itworld.com

* For all other inquiries, write Jodie Naze, Product Manager, 
  Newsletters at: jodie_naze@itworld.com

--------------------------------------------------------------------------------

PRIVACY POLICY
http://www2.itworld.com/CDA/ITW_Privacy_Policy 

Copyright 2000 ITworld.com, Inc., All Rights Reserved.

http://www.itworld.com 
