Home Next Intro Basic Shells Shell Syntax Built-In Commands Command Substitution Startup & Environment Pipes, Lists & Redirection Input & Output Using Files Design Considerations Functions Debugging Putting It All Together Appendix Code Examples

Preface

Shell programming was not something I wanted to do from the start, it kind of crept up on me over the years. You know how it is, you do something regular enough that it gets boring and you try to find short cuts. Well after my first UNIX training course I went back to the office and started to look at the support requirements and it soon became obvious that to do a good job something had to be done regarding the overload of administration on a detailed level as the system grew. Initially my scripts were small and dedicated , and to do the same thing for several users I just copied the script into their home directory and edited a few lines and off it went. After a few weeks, I spotted the error of my ways and created a directory for scripts that could be shared. I put the directory into everyone's path and started moving scripts into this central place. By editing the scripts and putting in variables, instead of hard coded values, I found I could make them generic enough for anybody to use, as long as the user's environment contained enough background information for the script to pick up and use.

A few months down the line and I saw another opportunity as I was aware there was a lot of common code in most of these scripts. Why keep copying all this code when I could call it from another file? Two things sprang to mind initially, one was the .profile, which I was already using to store users environment variables, the other was functions, which I had seen one of my friends use in a long script suite. I dug out the man pages for the shells and spent the next few days looking at sh, csh, and ksh in detail, trying out short test scripts to make sure I understood what was written. I had a look in my local book store for books on shell programming generally. Alas the only books available were very basic and covered what I had already learned. What I did pick up at this time was that there was a general disliking for the C Shell in most books I found. It was pointed out on numerous occasions how many bugs there were. I must admit, even the man pages themselves highlight several pages of bugs at the back. I was also aware that to fully support a networked system there were several files you had to be able to edit and fix when things changed. These are the basic system set up files and spool daemons etc. All of these files are of course written using the Bourne Shell. You become quite good at the Bourne Shell when you set up printer drivers for a networked drawing archival system with distributed printers and plotters.

What I started to see here was a language that was very succinct - terse, but to the point. It had few bugs - certainly no one remarked on them. It was also very portable in that all UNIX systems support it and make use of it exclusively for low level set up scripts and installation suites. I found this a bit of a nuisance because I was a C Shell programmer and I liked my cosy environment! But when I saw these functions used, I started to see real benefits - C Shell does not have functions. I converted a few scripts, it's not too difficult - just a few key word changes, the if syntax, etc. Then I put in a few functions to replace some common code. Well, look at that! The script is now only half the size and still does the same thing! What's more, if I change this function, all the scripts that call it are immediately updated too! This is neat! The rest, as they say, is history.

Shortcuts to Code Examples and Zipped Word Docs
.profile
Called each time you start a Bourne or Korn script. Calls all the other required profiles in sequence. Don't forget to add new profiles at the end of this list.
.profile_subroutine
Called from .profile to load each of the function (or subroutine) unit files (strings, dates, utils, etc) at each invocation
.profile_fun_date
Contains all the functions dealing with date formats and date transformations and manipulations.
.profile_fun_strg
Contains all the string, word, and character manipulation type functions.
.profile_fun_file
Contains all the file creation and deletion type functions which are used to administer temporary files and logfiles.
.profile_fun_dbas
Contains all the database access utilities both for SQL*Net 1 and SQL*Net 2 versions of the Oracle ™ network access utilities.
.profile_fun_move
Contains functions relating to file transfer and mail utilities.
.profile_fun_util
Contains function that don't fit into the other categories. This group generally get broken down when the list gets too long.
SHBOOK.ZIP
Contains My Shell Scripting Guide in Microsoft Word 6.0 format structured as a master document with 18 sections.
WEBSITE.ZIP
Contains My Shell Scripting Guide in HTML format structured as a local web site in 18 sections. Just access with a browser.

This list will be updated from time to time as new functions become available. I will endevour to keep the most up to date stuff in the EXAMPLES.ZIP file on a monthly basis. However, code which has not yet been integrated into the zip file can be found below as plain text.

ftp function .cshrc .kshrc .profile paths

Page 201
This page was brought to you by rhreepe@injunea.demon.co.uk