Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 1997 > 9704

Serious Shell Programming

Venkat Iyer

The aim of this article is to promote Bourne shell programming as an all-purpose alternative scripting language. I will describe some tricks and provide examples and explanations to demonstrate shell's little known and used features. New shell programmers can use the functions described here to ease shell programming restrictions, and experienced shell programmers may pick up a few tips. These examples are also available in source form as described later in the Availability section.

Why Shell

The C shell is without doubt a useful interactive shell, but for programming it is not much use. One major deficiency in the C shell is the absence of functions. The only way to reuse code in C shell is to write each function in a separate file and call each file as required. Doing something serious requires either large scripts with repeated pieces of code or many script files.

Shell is an inseparable part of UNIX. Every UNIX system shipped, from Minix 2.0.0 to Solaris 2.5.1, has shell in it, and most shells seem to be pretty compatible with each other. It is fairly easy to write scripts that will work on a variety of UNIX systems.

Shell is portable. All the examples in this article have been tested on a variety of systems - a 286 running Minix 1.7.4, Solaris 2.5, SunOS 4.1.4, DEC OSF1 V2.0, and HP-UX 9.05. On Minix though, these examples were run under /usr/bin/ash, and on HP, I used /bin/posix/sh. Note that /bin/sh will not work on either of these systems. I think these examples will work with any POSIX-compliant shell.

Shell scripts are typically written by systems administrators or software vendors providing installation scripts for their UNIX-based products. I have written lots of scripts in shell for everything from an issue tracking system to HTML generators.<>




MarketPlace

NEW! Numara FootPrints 9 - Service Desk Management
IT Service Management that Delivers. Real Value. Real Flexibility. Real Results. Free Demo.

Online Crash Analysis
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Visit Dell� Small and Medium Business Online Store
One Stop to Buy All Your Business IT Solutions. Browse Through Dell's Best Deals Online Now!

Wanna see your ad here?