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

Instant Answers to Your IT & Business Questions
Sign Up & Get Full Access To The Definitive Online Book Collection With SkillSoft's Books24x7�.

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.

BugSplat - Automatic Crash Analysis
Fast online exception analysis. Capture customer crash data online.

WinDev 11 - Powerful IDE
Develop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express version

Wanna see your ad here?