You are on page 1of 6

SUBJECT NAME : OPERATING SYSTEM

SUBJECT CODE: 303105251


B.Tech. CSE Year: 2nd 4th SEMESTER.

PRACTICAL NO -02

Aim: Study the basics of shell programming.


Theory:
Shell in Linux:
Shell in Linux is a text-based interface wherein users can enter command names, execute
programs, and manipulate files such as file handles, file permissions, and directories. Users can access
the shell through the terminal window or console, a window displaying a command prompt where
users can enter commands.

Features of Linux Shell:


Shell in Linux is a text-based interface wherein users can enter command names,
execute programs, and manipulate files such as file handles, file permissions, and
directories.
Users can access the shell through the terminal window or console, a window displaying
a command prompt where users can enter commands.

PIET CSE(PU) 11 2203031050321


SUBJECT NAME : OPERATING SYSTEM

SUBJECT CODE: 303105251


B.Tech. CSE Year: 2nd 4th SEMESTER.
The Linux shell is based on a scripting language called Bash (Bourne-Again Shell), the
default shell on most Linux systems.
Some basic commands in the Linux shell include- ls, cd, mkdir, touch, cp, mv, rm, etc.
With these basic commands, the Linux shell provides a wide range of advanced
commands and features that allow users to perform more complex tasks.
These include pipes, which allow users to connect the output of one command to the
input of another command. And also redirection, which allows users to redirect input or
output to a file.

What Is Shell Scripting In Linux?


Shell scripting in Linux is the process of creating and executing a series of commands in
a shell or command-line environment. It involves writing Linux shell scripts or a series
of commands in a text file using a scripting language that is interpreted by the shell. The
aim is to automate tasks or perform repetitive tasks quickly and efficiently. The shell
program is the default for many Linux distributions.
Conditional tests in shell scripting allow users to proceed with massive data amounts,
files to store and read data, and variables to store and read data, and these scripts may
contain functions.
Shell scripting is done using one of several scripting languages supported by the shell,
including Bash, Zsh, and Korn shell.
These scripting languages are designed to be simple and easy to learn, and they
provide a wide range of interactive features and functionality for writing powerful shell
scripts.

Steps to write and execute a script


1.Open the terminal. Go to the directory where you want to create your script.
2.Create a file with .sh extension.

3.Now it gets entered into the terinal where we can only read it.

PIET CSE(PU) 11 2203031050321


SUBJECT NAME : OPERATING SYSTEM

SUBJECT CODE: 303105251


B.Tech. CSE Year: 2nd 4th SEMESTER.

4.To get write permission press “I” ,so we can enter into insert mode ,at the bottom we
can see in ‘INSERT’ keyword.

5.Now we can able to write our shell script.

6.After writing our shellscript program to escape from the current terminal press “esc”
and then enter “:wq!” command to go back to execution mode.

7.Now you have only read access to your file you created,To get all permissions to that
file type “chmod 777 filename.extension” command.
PIET CSE(PU) 11 2203031050321
SUBJECT NAME : OPERATING SYSTEM

SUBJECT CODE: 303105251


B.Tech. CSE Year: 2nd 4th SEMESTER.
Before “chmod 777 filename.extension” command.

After entering “chmod 777 filename.extension” command.You get all permissions on that
file.

8.For printing type “./filename.extension” command.Now you will see output in the
terminal.

PROGRAM 01:
Write a shellscript program to check whether the given number is even or odd.

PIET CSE(PU) 11 2203031050321


SUBJECT NAME : OPERATING SYSTEM

SUBJECT CODE: 303105251


B.Tech. CSE Year: 2nd 4th SEMESTER.

PROGRAM 02:
Write a shell script program displaying the addition, subtraction, multiplication,, modulo
operations.

PROGRAM 03:
Write a shell script program for finding factorial of a number.

PIET CSE(PU) 11 2203031050321


SUBJECT NAME : OPERATING SYSTEM

SUBJECT CODE: 303105251


B.Tech. CSE Year: 2nd 4th SEMESTER.

PIET CSE(PU) 11 2203031050321

You might also like