System Programming
System Programming
OLAEWE
ASSISTANT SOFTWARE
DEVELOPER
[BSc. , M.PHIL]
The if...else...fi statement is the advanced form of the if...fi
control
statement
• It allows shell to execute statements in a more controlled
manner while making decision between two choices.
IF...ELSE...FI
STATEMENT
EXAMPLE
Write a program to test the maximum between two unequal numbers
IF...ELIF...ELSE...FI STATEMENT
The if...elif...fi statement is an advance form of control statement that enables Shell to make correct
decision out of several conditions.
EXAMPLE
Write a program to detect the type of triangle using its sides
THE CASE...ESAC STATEMENT
The while loop allows programmers to execute a set of commands repeatedly until some condition
occurs.
It is usually used when you need to manipulate the value of a variable repeatedly.
EXAMPLE
Here is a loop that counts from 0 to 7
THE FOR LOOP
The for loop in shell programming operates on a list of items.
That is, it repeats a set of commands for each and every item in the list.
The following example is used to display all the files starting with .bash and available in your home
directorate.
THE UNTIL LOOP
The until loop comes in handy whenever the need arises for us to execute a set of commands until a
condition becomes true.
THE SELECT LOOP
The select loop makes it much easier to create a numbered list of items or menu from which users can
select.
It is most useful when you need to ask the user to choose one or more items from a list of choices.
NESTING LOOPS
• Nesting is a concept in which a loop can be put inside another similar or different
loop.
• This nesting can go up to unlimited number of times based on your requirements.
• The syntax below illustrates how to nest a while loop in another while loop. Other
loops can be nested in a similar way.
In the example below, a countdown while loop is added to a loop that counts
from 0 – 9.
• Note how echo -n works in this example.
• The -n option prevents echo from printing a new line character.
FUNCTIONS
Enables us to break down the overall functionality of a script into smaller, logical
subsections.
It is an excellent way to facilitate code reuse
INTRODUCTION TO VI EDITOR
There are several ways files can be edited in UNIX and
• one of the best ways is using screen-oriented text editor vi.
• The vi editor can be used to edit an existing file or to create a new file from
scratch.
• Also, it can just be used to read a text file.
• Other editors: emacs, ed, ex etc..
• The vi editor is considered the de facto standard editor because:
It's usually available on all the flavours of UNIX system.
Its implementations are very similar across board.
It requires very few resources.