Creating Global Functions with the Korn Shell
Rainer Raab
Scripting and UNIX systems administration go hand in hand. Writing
scripts to automate repetitive tasks is necessary if you want to find the time
to work on other things, such as tightening security on the systems you manage,
migrating applications to promote server utilization, capacity planning, and
system tuning. These types of tasks often fall at the bottom of the food chain
if you are in a typical shop, constantly putting out the fires started by buggy
applications, compounded by poor vendor support, and unreliable hardware. They
also lose priority if you are supporting a development team with a time to market
of 3-6 months for their application and the developers expect you to manage
the test, staging, and production environments, along with application deployment
and installation scripts. Fortunately, most UNIX variants provide an ideal tool
for developing and deploying scripts -- the Korn shell.
The Korn shell is not just a command interpreter; it provides a powerful and versatile programming language for the rapid development of automation scripts and the capability to write globally accessible functions. In its basic form, a Korn shell script is a series of shell commands, strung together in an executable file. In its most advanced form, a Korn shell script may utilize built-in shell commands that provide support for arrays, integer arithmetic and arithmetic conditions, advanced UNIX I/O redirectors, and functions. It is the support for functions that allows the rapid development of scripts that provide solutions to the tasks of routine UNIX systems administration.
Defining Global Functions Korn shell functions, known as procedures or subroutines in other programming languages, allow for the organization of related shell commands by name. By organizing shell commands into functions, long shell scripts are easier to read and follow, and thus maintain.
|