Lab03 - Introduction To Shell Programming
Lab03 - Introduction To Shell Programming
Introduction
Objective
The Objective of this lab is to familiarize yourself with Ubuntu ad then proceed to shell
programming.
Description:
This lab has been designed to get even better insight of the shell programming. By the end of this
lab you‘ll be able to solve more complex problems in Linux using shell.
Tools/Software Requirement:
Linux (Ubuntu)
Introduction to Shell:-
shell is an command language interpreter that executes commands read from the standard
input device (keyboard) or from a file. It is not part of system kernel, but uses the system
kernel to execute programs, create files etc.
3): ./myscript.sh
Loops in shell:-
1):- For loop
Syntax:-
for { variable name } in { list }
do
execute one for each item in the list until the list is
not finished (And repeat all statement between do and done)
done
Syntax:-
while [ condition ]
do
command1
command2
command3
..
....
Done
case $NUM in
1) echo "one" ;;
2) echo "two" ;;
3) echo "three" ;;
4) echo "four" ;;
5) echo "five" ;;
6) echo "six" ;;
7) echo "seven" ;;
8) echo "eight" ;;
9) echo "nine" ;;
10) echo "ten" ;;
*) echo "INVALID NUMBER!" ;;
esac
The 1,2,3 are the values that could possibly be contained in $NUM.The * character at the end
indicates how you’ll handle any other case just like “Default case” in switch case scenario of
if statements :-
if condition ; then
commands
fi
if else statements:-
if condition ; then
commands
else
commands
fi
Groups: - you may work in the groups of two. But please note that you have to submit one
lab report per group (with the names of both group members written on it).If you submit
multiple submissions per group it will be considered as plagiarism.
Task # 0
Write a shell script to input name and his batch number from the student and display this
information on terminal.
Task # 1
Write a shell script to print the multiplication table for the given number. You can take that
number as input from the user.
Note:- the expression calculation (explained in demo) looks like this:-
x=`expr $x + 1`
Task # 2
Write a shell script to make a simple calculator which should be capable of performing basic
calculations. Also add a feature of repeated inputs from the user.
Task # 3
Task # 4
Write a shell script to find no. of lines and words in a given file. You can take file name as
input from the user.
Note :- Please explore the command wc.
Deliverables
Upload the document containing codes as well as screenshots on LMS .