Bourne Shell Scripting

There are variants of the Bourne Shell. The Bourne Shell (/bin/sh) was developed by Stephen Bourne at Bell Labs. It was released in 1979 with the release of version 7 of UNIX. Although it is used as an interactive command interpreter, meaning that the program is the principal program running when they login for an interactive session. It was also intended as a scripting language that would execute like a canned program using a framework of logic that executes other programs.

Introduction

There are several Bourne Shell variants available on open systems to perform rudimentary shell scripting. The traditional Bourne Shell (“sh”) has been fading in the sunset though it is lightweight for use by the OS. I have found that for the user environment, Bash (Bourne Again Shell) is the logical choice that is packaged on all open system platforms and consistently named (/usr/bin/bash). From a scripting standpoint, though I prefer Korn, Bash is universal enough and has a similar notion of the advanced Korn features, though not as robust (e.g. smart variable substitution options/functionality).

The Korn Shell was originally developed by David Korn, until about 2000, the source code was proprietary code licensed by AT&T. In about 2000, the code was released to open source. There are two significant versions released - KSH 1988 and KSH 1993. On Linux, an open source version pdksh is roughly the 1993 version. On proprietary UNIX systems, both the traditional Korn 1988 and 1993 are supplied, though not consistently named across OS variants as an executable.

What is the Purpose of the Shell?

The shell concept was originally developed as a way for an end user to start the execution of a program and run on top of the operating system. It was also a simple way to provide a simplistic code base to perform a stacked execution of commands to produce a desired end result. If you only need simple logic branching and don’t require computational math a shell script is suitable. A common mistake that scripters often do is parsing multiple lines out of an input source that have to be considered as one (e.g. parsing through an LDIF). Another tool should be used such as Perl or Python for advanced scripting.

Arrays are basic. There is only one type available - the indexed array. To replicate a key/value oriented array, you have to use two arrays that are loaded simultaneously. In parsing the array, you have to use script logic to parse the “key” array and use that index on the “value” array. There is no ability to perform fuzzy matches. You have to condition on the whole string for a match.

One last point to make is over environmental variable scope. Variables are all in the “global scope” unlike other scripting languages. That means that the contents of a named variable is universally available throughout the script using the same name. Other languages handle named variables locally within the scope of a function unless it is declared to be global. Where one function is subordinate to another function, it’s variables are inherited from its parent.

Here are a couple good tutorial and reference guides:

Last modified February 25, 2021: version 2.0 (70b449f)