SlideShare a Scribd company logo
Dr. D. P.
Mishra
Digitally signed by Dr. D. P. Mishra
DN: cn=Dr. D. P. Mishra, o=durg,
ou=BIT, email=dpmishra@bitdurg.
ac.in, c=IN
Date: 2023.03.13 12:39:50 +05'30'
#!/bin/sh
# This script performs basic mathematical operations
echo "Enter the first number: "
read num1
echo "Enter the second number: "
read num2
# Addition
add=$((num1 + num2))
echo "The sum of $num1 and $num2 is $add.“
# Subtraction
sub=$((num1 - num2))
echo "The difference of $num1 and $num2 is $sub."
# Multiplication
mul=$((num1 * num2))
echo "The product of $num1 and $num2 is
$mul."
# Division
if [ $num2 -ne 0 ]
then
div=$((num1 / num2))
echo "The quotient of $num1 and $num2
is $div."
else
echo "Cannot divide by zero."
fi
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
5.1- Shell Script for performing basic
mathematical operations
#!/bin/sh
# This script swaps the values of
two numbers using a temporary
variable
echo "Enter the first number: "
read num1
echo "Enter the second number: "
read num2
echo "Before swapping, num1 is
$num1 and num2 is $num2."
# Swap the values of num1 and num2
using a temporary variable
temp=$num1
num1=$num2
num2=$temp
echo "After swapping, num1 is $num1
and num2 is $num2."
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
5.2- Shell Script for Swapping values of two
numbers using temporary variables
#!/bin/sh
# This script swaps two numbers
without using a temporary variable
echo "Enter the first number: "
read num1
echo "Enter the second number: "
read num2
echo "Before swapping, num1 is
$num1 and num2 is $num2."
# Swap the values of num1 and num2
without a temporary variable
num1=$((num1 + num2))
num2=$((num1 - num2))
num1=$((num1 - num2))
echo "After swapping, num1 is $num1
and num2 is $num2."
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
5.3- Shell Script to swap two numbers
without Temporary Variables
5.4- Shell Script for determining whether
number is even or odd
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
#!/bin/sh
# This script determines whether a number is even or odd
echo "Enter a number: "
read num
if [ $((num % 2)) -eq 0 ]
then
echo "$num is even."
else
echo "$num is odd."
fi
5.5:Task/Assignment
• Write a shell script to input marks of five subjects Physics, Chemistry,
Biology, Mathematics and Computer. Calculate percentage and grade
according to following logic:
• Percentage >= 90% : Grade A,
• Percentage >= 80% : Grade B,
• Percentage >= 70% : Grade C,
• Percentage >=60% . Grade D,
• Percentage >= 40% : Grade E,
• Percentage < 40% : Grade F.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Basic Shell Programs

More Related Content

PDF
Control flow and related shell cripts
DOCX
32 shell-programming
PDF
Operating_System_Lab_ClassOperating_System_2.pdf
PPTX
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
DOCX
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
DOCX
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
DOCX
1 ECE 175 Computer Programming for Engineering Applica.docx
PDF
python.pdf
Control flow and related shell cripts
32 shell-programming
Operating_System_Lab_ClassOperating_System_2.pdf
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx
Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2.docx
1 ECE 175 Computer Programming for Engineering Applica.docx
python.pdf

Similar to Basic Shell Programs (20)

DOCX
Pseudo code practice problems+ c basics
PPTX
PRACTICAL FILE(COMP SC).pptx
PPTX
Exploring Control Flow: Harnessing While Loops in Python
PDF
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
PDF
Avoiding Hardware Aliasing
PDF
cluster(python)
DOCX
project 6cards.pyimport randomclass Card( object ).docx
DOCX
#include iostreamusing namespace std;double sumNums(
PPTX
AOS_Module_3ssssssssssssssssssssssssssss.pptx
DOCX
c plus plus programsSlide
KEY
No comment
PDF
Introduction to base shell scripting
DOC
Programs.doc
PDF
AI-Programs.pdf
PDF
Python_Cheat_Sheet_Keywords_1664634397.pdf
PDF
Python_Cheat_Sheet_Keywords_1664634397.pdf
DOCX
ECE-PYTHON.docx
PPTX
Python Homework Help
PPT
PDF
Recitation2IntroductionToPython.pptx.pdf
Pseudo code practice problems+ c basics
PRACTICAL FILE(COMP SC).pptx
Exploring Control Flow: Harnessing While Loops in Python
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
Avoiding Hardware Aliasing
cluster(python)
project 6cards.pyimport randomclass Card( object ).docx
#include iostreamusing namespace std;double sumNums(
AOS_Module_3ssssssssssssssssssssssssssss.pptx
c plus plus programsSlide
No comment
Introduction to base shell scripting
Programs.doc
AI-Programs.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
ECE-PYTHON.docx
Python Homework Help
Recitation2IntroductionToPython.pptx.pdf
Ad

More from BIT DURG (20)

PDF
B VOC Level-7: Design & Implementation of Biometric System
PDF
B VOC Level-7: Finger Print and Sign Language
PDF
B VOC Level-7 Face & IRIS Recognition based on determining shape and size of ...
PDF
B VOC Level-7: Biometric Comparision and Evaluation
PDF
B VOC Level-7: Biometric Recognition that aims towards establishing one’s ide...
PDF
HTML_DOM
PDF
JavaScript
PDF
Understanding WWW
PDF
Computer Networks
PDF
Computer Basics
PDF
ISDN & ATM
PDF
Transport Control Protocol
PDF
Routing Protocols
PDF
Internet Protocol.pdf
PDF
Intternetworking With TCP/IP
PDF
Computer Network Basics
PDF
MySQL
PDF
Types of Linux Shells
PDF
File Access Permission
PDF
Filters & Vi Editor
B VOC Level-7: Design & Implementation of Biometric System
B VOC Level-7: Finger Print and Sign Language
B VOC Level-7 Face & IRIS Recognition based on determining shape and size of ...
B VOC Level-7: Biometric Comparision and Evaluation
B VOC Level-7: Biometric Recognition that aims towards establishing one’s ide...
HTML_DOM
JavaScript
Understanding WWW
Computer Networks
Computer Basics
ISDN & ATM
Transport Control Protocol
Routing Protocols
Internet Protocol.pdf
Intternetworking With TCP/IP
Computer Network Basics
MySQL
Types of Linux Shells
File Access Permission
Filters & Vi Editor
Ad

Recently uploaded (20)

PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
Well-logging-methods_new................
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
bas. eng. economics group 4 presentation 1.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
DOCX
573137875-Attendance-Management-System-original
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Construction Project Organization Group 2.pptx
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
737-MAX_SRG.pdf student reference guides
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Operating System & Kernel Study Guide-1 - converted.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
III.4.1.2_The_Space_Environment.p pdffdf
Well-logging-methods_new................
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
bas. eng. economics group 4 presentation 1.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
573137875-Attendance-Management-System-original
OOP with Java - Java Introduction (Basics)
Construction Project Organization Group 2.pptx
Fundamentals of safety and accident prevention -final (1).pptx
Foundation to blockchain - A guide to Blockchain Tech
Internet of Things (IOT) - A guide to understanding
737-MAX_SRG.pdf student reference guides
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
additive manufacturing of ss316l using mig welding
Automation-in-Manufacturing-Chapter-Introduction.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...

Basic Shell Programs

  • 1. Dr. D. P. Mishra Digitally signed by Dr. D. P. Mishra DN: cn=Dr. D. P. Mishra, o=durg, ou=BIT, email=dpmishra@bitdurg. ac.in, c=IN Date: 2023.03.13 12:39:50 +05'30'
  • 2. #!/bin/sh # This script performs basic mathematical operations echo "Enter the first number: " read num1 echo "Enter the second number: " read num2 # Addition add=$((num1 + num2)) echo "The sum of $num1 and $num2 is $add.“ # Subtraction sub=$((num1 - num2)) echo "The difference of $num1 and $num2 is $sub." # Multiplication mul=$((num1 * num2)) echo "The product of $num1 and $num2 is $mul." # Division if [ $num2 -ne 0 ] then div=$((num1 / num2)) echo "The quotient of $num1 and $num2 is $div." else echo "Cannot divide by zero." fi Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg 5.1- Shell Script for performing basic mathematical operations
  • 3. #!/bin/sh # This script swaps the values of two numbers using a temporary variable echo "Enter the first number: " read num1 echo "Enter the second number: " read num2 echo "Before swapping, num1 is $num1 and num2 is $num2." # Swap the values of num1 and num2 using a temporary variable temp=$num1 num1=$num2 num2=$temp echo "After swapping, num1 is $num1 and num2 is $num2." Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg 5.2- Shell Script for Swapping values of two numbers using temporary variables
  • 4. #!/bin/sh # This script swaps two numbers without using a temporary variable echo "Enter the first number: " read num1 echo "Enter the second number: " read num2 echo "Before swapping, num1 is $num1 and num2 is $num2." # Swap the values of num1 and num2 without a temporary variable num1=$((num1 + num2)) num2=$((num1 - num2)) num1=$((num1 - num2)) echo "After swapping, num1 is $num1 and num2 is $num2." Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg 5.3- Shell Script to swap two numbers without Temporary Variables
  • 5. 5.4- Shell Script for determining whether number is even or odd Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg #!/bin/sh # This script determines whether a number is even or odd echo "Enter a number: " read num if [ $((num % 2)) -eq 0 ] then echo "$num is even." else echo "$num is odd." fi
  • 6. 5.5:Task/Assignment • Write a shell script to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following logic: • Percentage >= 90% : Grade A, • Percentage >= 80% : Grade B, • Percentage >= 70% : Grade C, • Percentage >=60% . Grade D, • Percentage >= 40% : Grade E, • Percentage < 40% : Grade F. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg