Writing Shell Scripts

Although in principle a shell command that you define an alias for could be quite long and complex, in practice there can be problems, particularly if the command itself contains quotation marks. However, you can create an alias only for a single command. So if you want to execute a more complex command, or if you want to execute multiple commands, you are moving into the area of shell scripts. A shell script is a program written to be interpreted by the shell. Essentially it is just a list of shell commands to be executed one after the other, but it can contain conditionals and other programming constructs, giving it the power of a real program. Here we consider scripts to be run by the bash shell (bash scripts).

Shell scripts offer a simple means of automating tasks, provided those tasks are not too complex. If the length and complexity of a shell script goes beyond certain limits, then it might be that a shell script is not the best way to perform the task at hand.

| f - - p In the next sections, we offer some examples of simple shell scripts. Our goal is to show the basic logic of shell scripts and how they act as a getting-started guide. As with so much else in this book, shell scripting is a subject on which entire books have been written. Here we give a few examples of the basic concepts to get you started and experimenting.

Was this article helpful?

0 0

Post a comment