Generalities about shell programming

Interpreter commands of the Unix operating system provides, besides the possibility of execution of orders, a set of instructions that allows writing programs like those written in high level programming languages. Naturally, the possibilities of this language are much weaker than those of a language like C or Pascal, but there are applications where programming effort is much reduced. Besides commands “regular”, which appear in any operating system, Unix and provides plenty of tools, especially text files. Shell language is powerful and effective:
• Applications whose resolution involves several transactions in the shell commands;
• Applications that manipulate data as text files or lines of text;
• Applications that require consultation browse directories and file system;

Last but not least, when we do regular operations involving the use of shell commands, we can automate work by creating a batch file.
Batch file will call any sequence of commands stored in a disk file. The program will understand Shell script file that contains, besides orders execution control structures (decision and repetitive instructions) and variable. This chapter presents the most important concepts in programming scripts in Bourne Again Shell (BASH), the most widespread in Linux. To schedule under another shell, appropriate documentation should be consulted to see what the differences are.
Objects that compose a script are:
• Linux Commands;
• Variables:
1. User-defined variables;
2. Predefined variables (system);
3. Particular variable;
• Instructions for read / write:
1. read to read data;
2. echo to display data and messages;
• Instructions for Decision:
1. simple if-statement of decision;
2. Multiple decision-home instruction;
3. select-statement to create simple menus;
Iterative Instructions:
1. forum
2. while
3. Until
• Instructions jump:
1. Forced break out of a cycle
2. continuous-forces continued for the next cycle counter value
As you noticed, there is an unconditional jump instruction (goto), thus gaining programs readability. Placing instructions allow repetitive writing structured programs, unlike the “language” of the operating system MSDOS batch.
A script can receive command line arguments. Also, you can call from within a script, other scripts.


Scripts can be written using a text editor like vi, ed, emacs. Then it sets the right execution of the file name can be used as a regular command. The shell command will execute the file command.
An example of a simple batch file is:
pwd
ls-l
finger

Topics: , , , , , , , , , , , , , , , , , , , ,

Did you like this? Share it:

Watch tweets on:
  • You may also like

    1. Picture: Programming Language

      Programming Language

      This programming language, with the lowest possible name, was created right in 1971 by Dennis Ritchi...

    2. Picture: User Interface

      User Interface

      After the login process has been verified correct username and password, it changes the current cata...

    3. Picture: UNIX Basics

      UNIX Basics

      This section tries to present some basic knowledge about operating system, although it appeared in t...

    4. Picture: Loading the operating system

      Loading the operating system

      Exercise: Try to remember, without resort to the specification, process definition. Unix operating s...

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>