Control Mechanisms of the UNIX Shell
(Page 1 of 4 )
The power of an operating system is equal to the powers of the tools/programs it can provide. What you can do inside the operating system depends on the nature of the tools it offers you. However, you can have the most advanced and capable tools, yet suffer if you fail to put them to work in a correct and efficient way. This is where the control mechanism you have at your disposal enters the picture. Now then, what control mechanism will help us to exploit UNIX tools to their full capacities?
This article is part of a larger series in which I try to cover everything you should know about UNIX Shell programming. The knowledge you can amass here will be very helpful once you start to use UNIX-based operating systems like UNIX itself, FreeBSD, and so on.
With the tools/commands inside the UNIX Shell, you can automate most basic tasks and perform some advanced ones. If you had to do these tasks manually, with the mouse and a graphical interface, they would take much longer. So why waste your time?
When we talk about a concrete task to complete in the shell programs, in fact, we have a command or a command line that waits for execution. With command lines, we can give more than one command with the help of pipes, as I will be explaining in an article entitled Data Streams and the UNIX Shell. Due to this, we often refer to a concrete task as a pipeline. Pipelines are a sequence of commands connected via pipes.
In the control mechanism, a task is a command line. If, inside the command line, the performance of another command depends on the result of an assumption, we call that a command line condition. The order in which the commands are executed we call the controlling mechanism. For this, the shell uses a couple of control structures.
If you've encountered other structured programming languages, you already know that the control mechanism should implement two basic types. One type is decision implementation (the if-then-else structure) and the second is loops. With the help of these two, we can simulate the control of any program.
The creators of the UNIX Shell were inspired by the control mechanism of ALGOL68. In the following articles, I will present to you all the structures that help us in implementing these two basic control mechanisms and how you can exploit them to their utmost. In this first article on the topic, I will look at decision making.
Next: The true/false statement >>
More Miscellaneous Articles
More By Gabor Bernat