0% found this document useful (0 votes)
12 views14 pages

Los MP

Los microproject

Uploaded by

rajvardhan0266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

Los MP

Los microproject

Uploaded by

rajvardhan0266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Abstract

Our Micro project is based of Shell Programming in Linux Operating system. Linux is an open
source operating system (OS). An operating system is the software that directly manages a system’s
hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware
and makes the connections between all of your software and the physical resources that do the work.

We saw that shells are interactive, they accept commands as input from users and execute them. But if we
want to execute a bunch of commands again and again (like a loop), we have to type in all commands each
time in the terminal.

1
1.Rationale :
Operating System is the interface between the user and the computer system. Nowadays LINUX is
one of the most widely used operating system. Knowledge of LINUX operating system is essential
as it provides many features such as multitasking, multiuser, security etc. which are mainly used in
both server and workstation systems. So, this course will enable the students to inculcate the basics
of LINUX Operating System, writing Shell scripts as well as administer the network.

2. Aim And Benefits :


1)Learning what is shell Programming.
2)Different statements in Shell Scripting.

3. Course Outcomes :
1)Use Basic Linux commands and utilities.
2) Develop Shell program for solving different problems.

4. Actual Methodology Followed :


1)We collect all data required for our micro-project.
2)Learn the basics of shell script.
3)Learn the commands and programing in linux.

2
Action Plan:

Sr.No. Details of activity Start Finish Responsible


Date Date Team
member
1 Selected the topic for micro- 03-02-23 10-02-23
project Pavan
2 We organised things required 11-02-23 25-02-23
for our project Smita
3 We browsed the internet for 27-02-23 06-03-23
information and raw data Vijay
4 We attended extra lectures 10-03-23 20-03-23
for our project topic Pavan
5 We made points/notes on the 24-03-23 31-03-23
information we collected Smita
6 We created a word document 31-03-23 10-04-23
with help of our teacher Vijay
7 We made corrections by 10-04-23 17-04-23 Pavan
discussing with our teacher
8 We also created a PDF 24-04-23 29-04-23
document to make a hard Vijay
copy of the report

3
Introduction

Usually, shells are interactive, which means they accept commands as input from users and
execute them. However, sometimes we want to execute a bunch of commands routinely, so we
have to type in all commands each time in the terminal.
As a shell can also take commands as input from file, we can write these commands in a file
and can execute them in shell to avoid this repetitive work. These files are called Shell
Scripts or Shell Programs. Shell scripts are similar to the batch file in MS-DOS. Each shell
script is saved with `.sh` file extension e.g., myscript.sh.
A shell script has syntax just like any other programming language. If you have any prior
experience with any programming language like Python, C/C++ etc. It would be very easy to
get started with it.
A shell script comprises the following elements –
• Shell Keywords – if, else, break etc.
• Shell commands – cd, ls, echo, pwd, touch etc.
• Functions
• Control flow – if..then..else, case and shell loops etc.

Types of Shell
There are two main shells in Linux:

1. The Bourne Shell: The prompt for this shell is $ and its derivatives are listed below:

• POSIX shell also is known as sh


• Korn Shell also knew as sh
• Bourne again shell also knew as bash (most popular)

2. The C shell: The prompt for this shell is %, and its subcategories are:

• C shell also is known as csh


• Tops C shell also is known as tcsh

4
Concepts :
Why do we need shell scripts?

There are many reasons to write shell scripts:


• To avoid repetitive work and automation
• System admins use shell scripting for routine backups.
• System monitoring
• Adding new functionality to the shell etc.

Some Advantages of shell scripts

• The command and syntax are exactly the same as those directly entered in the
command line, so programmers do not need to switch to entirely different
syntax
• Writing shell scripts are much quicker
• Quick start
• Interactive debugging etc.

Some Disadvantages of shell scripts

• Prone to costly errors, a single mistake can change the command which might
be harmful.
• Slow execution speed
• Design flaws within the language syntax or implementation
• Not well suited for large and complex task
• Provide minimal data structure unlike other scripting languages. etc.

What are Shell Variables?

As discussed earlier, Variables store data in the form of characters and numbers. Similarly, Shell
variables are used to store information and they can by the shell only.

5
Conditional Statements :

There are total 5 conditional statements which can be used in bash programming
1. if statement
2. if-else statement
3. if..elif..else..fi statement (Else If ladder)
4. if..then..else..if..then..fi..fi..(Nested if)
5. switch statement

1.if statement

This block will process if specified condition is true.

Syntax:

if [ expression ]
then
statement
fi

Example :

6
2.if-else statement

If specified condition is not true in if part then else part will be execute.

Syntax

if [ expression ]
then
statement1
else
statement2
fi

Example :

7
3.if..elif..else..fi statement (Else If ladder)

To use multiple conditions in one if-else block, then elif keyword is used in shell. If
expression1 is true then it executes statement 1 and 2, and this process continues. If
none of the condition is true then it processes else part.

Syntax

if [ expression1 ]
then
statement1
statement2
elif [ expression2 ]
then
statement3
statement4
else
statement5
fi

Example :

8
4.if..then..else..if..then..fi..fi..(Nested if)

Nested if-else block can be used when, one condition is satisfies then it again checks
another condition. In the syntax, if expression1 is false then it processes else part, and
again expression2 will be check.

Syntax:

if [ expression1 ]
then
statement1
statement2

else
if [ expression2 ]
then
statement3

fi
fi

Example :

9
5.switch statement

case statement works as a switch statement if specified value match with the pattern
then it will execute a block of that particular pattern
When a match is found all of the associated statements until the double semicolon (;;) is
executed.
A case will be terminated when the last command is executed.
If there is no match, the exit status of the case is zero.

Syntax:

case in
Pattern 1) Statement 1;;
Pattern n) Statement n;;
esac

Example :

10
Looping Statements :
There are total 3 looping statements that can be used in bash programming
1. while statement
2. for statement
3. until statement

1.while Statement :
Here the command is evaluated and based on the resulting loop will execute, if the command is raise
to false then the loop will be terminated.
Synatx :
while <condition>
do

<command 1>
<command 2>
<etc>
done

Example :

11
2.for Statement :
The for loop operates on lists of items. It repeats a set of commands for every item in a list.
Here var is the name of a variable and word1 to wordN are sequences of characters separated by spaces
(words). Each time the for loop executes, the value of the variable var is set to the next word in the list of
words, word1 to wordN.

Synatx :
for <var> in <value1 value2 ... valuen>
do
<command 1>
<command 2>
<etc>
done

Example :

12
3.until Statement :

The until loop is executed as many times as the condition/command evaluates too false. The loop
terminates when the condition/command becomes true.
Synatx :
until <condition>
do

<command 1>
<command 2>
<etc>
done

Example :

13
Skills Developed :

1) Learn basic Linux commands and shell scripting.


2) Learn conditional statements in shell scripting.
3) Learn looping statements in shell scripting.

Conclusion:

In our project Shell Programming in Linux we learn to write a series of commands for the shell to
execute. It can combine lengthy and repetitive sequences of commands into a single and simple
script that can be stored and executed anytime which, reduces programming efforts. Kernel is the
nucleus of the operating systems, and it communicates between hardware and software.Shell is a
program which interprets user commands through CLI like Terminal.The Bourne shell and the C
shell are the most used shells in Linux.Linux Shell scripting is writing a series of command for the
shell to execute.Shell variables store the value of a string or a number for the shell to read.Shell
scripting in Linux can help you create complex programs containing conditional statements, loops,
and functions.

Reference :

https://www.geeksforgeeks.org/introduction-linux-shell-shell-scripting/

https://www.onlinegdb.com/online_bash_shell

https://www.tutorialspoint.com/unix/unix-shell-loops.htm

14

You might also like