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

Shell Program

The document provides an overview of shell scripting, including how to execute shell scripts on Windows and the basic constructs of shell programming. It outlines various operations such as creating, inserting, displaying, searching, deleting, and modifying student records, along with the corresponding shell commands for each operation. Additionally, it emphasizes the importance of using functions and a menu-driven approach for user interaction.

Uploaded by

shirkebharti18
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)
3 views14 pages

Shell Program

The document provides an overview of shell scripting, including how to execute shell scripts on Windows and the basic constructs of shell programming. It outlines various operations such as creating, inserting, displaying, searching, deleting, and modifying student records, along with the corresponding shell commands for each operation. Additionally, it emphasizes the importance of using functions and a menu-driven approach for user interaction.

Uploaded by

shirkebharti18
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

Assignment 2

Shell Program
Shell Scripting
get the name of your shell prompt
echo $SHELL

Bash is a Unix shell and command language which can run Shell Script files

If you are working on Windows machine


You do not need to install Ubuntu or any other Linux Distros unless your
scripts need the support of the real Linux kernel.

We can use any of the methods.

1. Execute Shell Script file using WSL (Windows subsystem for Linux)
2. Execute Shell Script using Ubuntu on Windows 10
Shell scripts have several required constructs that tell the shell environment what to do and
when to do it.

The shell is, a real programming language, complete with variables, control structures, etc.

echo "What is your name?" - to print something

read command which takes the input from the keyboard and assigns it as the value of the
variable
read x
echo “$x”

Assigning value simply, abc = “hello”


echo “$abc”

We can unset the value too.


unset abc
Perform various operations using external programs
like, expr or awk

There must be spaces between operators and


expressions.
The complete expression should be enclosed between ‘
‘,backtick.
echo "Enter the Number"
read n
r =`expr $n % 2`
if [ $r -eq 0 ]
then echo "$n is Even number"
else
echo "$n is Odd number"
fi
echo "Enter a Number"
read n
i=`expr $n - 1`
fact=1
while [ $i -ge 1 ]
do
fact=$((fact * n))
n = $(( n - 1))
done
echo "The Factorial of the given Number is $fact"
echo "Enter your lucky number"
read n
case $n in
101) echo "You got 1st prize" ;;
510) echo "You got 2nd prize" ;;
999) echo "You got 3rd prize" ;;
*) echo "Sorry, try for the next time" ;;
esac
Hello () {
echo "Hello World"
}
#call your function
Hello

$ ./[Link]

Hello () {
echo "Hello World $1 $2"
}

# Invoke your function


Hello abc xyz
Shell program for handling Student Record

Operations expected:
1) Create record

2) Insert record

3) Display record

4) Search record

5) Delete record

6) Modify record
⚫ Create separate function for each operation.
⚫ Make the program menu driven; take choice from
user to select an operation on the record
⚫ Use proper shell commands as a part of each
function
Commands used in the operations

1) Create record: touch


2) Insert record: read ,echo
3) Display: cat
4) Search: echo, read, grep
5) Delete: echo,read,grep with its variation -v,mv
6) Modify: echo,read,grep with its variation -v,mv
Use switch case to make it menu driven

You might also like