SlideShare a Scribd company logo
1 of 12
Download to read offline
1
Solution manual of Shell programming Assignment – 2
1. Write a Shell Script to find the reverse of a given number Using WC.
Shell Script Output
2. Write a Shell Script to generate Fibonacci Series.
Shell Script Output
3. Write a Shell Script to display Mathematical Table for a given number
Shell Script
2
Output
4. Write a Shell Script to copy the content of a file to another file.
Shell Script
Output
3
5. Write a Shell Script to count the number of Vowels, Number of Consonants and Number
of digits present in a given String.
Shell Script
Output
4
6. Write a Shell Script to accept file name & convert its contents from lower to upper case.
Shell Script
Output
7. Write a shell script that will receive a name interactively from the user during execution
and prints a welcome message.(Say Hello <entered name>.Welcome to CSE Dept.,
Kalyani Govt. Engg. College !).
Shell Script
Output
8. Write a shell script that will receive a name interactively from the user during execution
and prints greetings according to the system time. (Example: say user enters “Anirban”
and if the system is less than 12.00 AM then the script will print : “Good Morning
Anirban” else if the system time is greater than 12.00 AM but less than 6.00 PM then
prints “Good After Noon Anirban” else if the system time is greater than 6.00 PM but
less than 8.00 PM then “Good Evening Anirban” else if the system time is greater than
8.00 PM but less than 12.00 PM then “Good Night Anirban”).
5
Shell Script
Output
9. Write a shell script that will receive a text filename(which contents a paragraph)
interactively from the user during execution and prints the following according to the
number of words present in the file: SHORT FILE(if the number of words is less than
100), MEDIUM FILE(if the number of words is greater than 100 but less than 350) ,
LARGE FILE( words greater than 350 but less than 500) and VERY LARGE FILE(words
greater than 500).
Shell Script
6
Output
10.Write a shell script that will receive a text filename as input and prints OFFICIAL FILE if
the first line of the file contains the string “KGEC” only else prints UNOFFICIAL FILE. If
the file is an OFFICIAL FILE then the program will prints number of words and characters
present in the first 10 lines, it also appends string “Accessed on: <current date-time
stamp>” at the end of the file.
Shell Script
Output
11.Write a shell script (check_exam.sh) that will use a file “exam_schedule.txt” to check
whether there is any exam today or not. If there is no exam today then it will print: NO
7
EXAM TODAY. The file “exam_schedule.txt” must contain three fields as EXAM
DATE(dd/mm/yyyy), EXAM TIME and EXAM PAPER. For example:
03/02/2014 10.00AM OPTICAL_NETWORK
04/02/2014 10.00AM IMAGE_PROCESSING
……… ……….. ……………..
Shell Script
Output
12.Write a shell script that will take the basic salary (BS) as runtime input from the user and
calculates the DA (5% if BS is less than or equal to 10,000, above 10,000 it becomes
15%), HRA(5% if BS is less than or equal to 10,000, above 10,000 it becomes 7%) and
finally calculates the gross salary(gross salary=BS+DA+HRA).
8
Shell Script
Output
13.Write a shell script to display the following menu:
i. Length of the string
ii. Reverse of the string
iii. Copy one string to another.
Shell Script
echo "Enter a string: "
read str
echo "i. Length of string"
echo "ii.Reverse of the string"
echo "iii. copy one string into another."
echo "Enter your choice: "
read c
case "$c" in
i)x=`echo $str | wc -c`
x=`expr $x - 1`
echo "Length is : $x";;
ii)x=`echo $str | wc -c`
x=`expr $x - 1`
while [ $x -gt 0 ]
do
c=`echo $str | cut -c $x`
s=$s$c
x=`expr $x - 1`
done
echo "The Reverse of string is : $s";;
iii)s=$str
echo "The copied string is : $s";;
esac
9
Output
14.Write a shell script to check whether a given number is prime or not.
Shell Script
echo "Enter a number: "
read num
i=2
f=0
while [ $i -le `expr $num / 2` ]
do
if [ `expr $num % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "The number is composite"
else
echo "The number is Prime"
fi
Output
15.Write a shell script to check whether a given number is an Armstrong number or not.
Shell Script
echo "Enter a number: "
read c
x=$c
sum=0
r=0
n=0
while [ $x -gt 0 ]
do
r=`expr $x % 10`
n=`expr $r * $r * $r`
sum=`expr $sum + $n`
x=`expr $x / 10`
done
if [ $sum -eq $c ]
then
echo "It is an Armstrong Number."
10
else
echo "It is not an Armstrong Number."
fi
Output
16.Write a shell script to find the sum of the first n numbers.
Shell Script
echo "Enter a number: "
read num
i=1
sum=0
while [ $i -le $num ]
do
sum=`expr $sum + $i`
i=`expr $i + 1`
done
echo "The sum of first $num numbers is: $sum"
Output
17.Write a shell script to find a sum of given no and to check out to see if it is even or odd.
Shell Script
echo "Enter a number: "
read n
sum=0
x=$n
r=0
while [ $x -gt 0 ]
do
r=`expr $x % 10`
sum=`expr $sum + $r`
x=`expr $x / 10`
done
if [ `expr $sum % 2` -eq 0 ]
then
echo "The sum of $n is $sum and it is even"
else
echo "The sum of $n is $sum and it is odd"
fi
11
Output
18.Write a shell script to find a factorial of a given number.
Shell Script
fact=1
ie=1
echo -e "Enter a number:c"
read a
while [ $ie -le $a ]
do
fact=`expr $fact * $ie`
ie=`expr $ie + 1`
done
echo -e "Multilpication of $a number is $fact."
Output
19.Write a shell script that takes 2 numbers through K/B and finds the value of first number
raised to the power of second.
Shell Script
echo "Enter a number: "
read a
echo "Enter Power: "
read p
i=1
ans=1
while [ $i -le $p ]
do
ans=`expr $ans * $a`
i=`expr $i + 1`
done
echo "Answer of $a^$p is $ans"
Output
20.Write a shell script to read a string through keyboard and check whether it is
palindrome or not.
Shell Script
echo "Enter a string: "
12
read s
len=`echo $s | wc -c`
while [ $len -gt 0 ]
do
st=`echo $s | cut -c $len`
str=$str$st
len=`expr $len - 1`
done
if [ $str = $s ]
then
echo "String Palindrome"
else
echo "string is not palindrome"
fi
Output

More Related Content

What's hot

Restaurant Project by Amit Mangukiya
Restaurant Project by Amit MangukiyaRestaurant Project by Amit Mangukiya
Restaurant Project by Amit Mangukiya
Amit Mangukiya
 

What's hot (20)

Project Proposel Documentation
Project Proposel  DocumentationProject Proposel  Documentation
Project Proposel Documentation
 
Tech Smart Canteen management
 Tech Smart Canteen management Tech Smart Canteen management
Tech Smart Canteen management
 
Restaurant Project by Amit Mangukiya
Restaurant Project by Amit MangukiyaRestaurant Project by Amit Mangukiya
Restaurant Project by Amit Mangukiya
 
Online Library management system proposal by Banuka Dananjaya Subasinghe
Online Library management system proposal by Banuka Dananjaya SubasingheOnline Library management system proposal by Banuka Dananjaya Subasinghe
Online Library management system proposal by Banuka Dananjaya Subasinghe
 
Medical store management system
Medical store management systemMedical store management system
Medical store management system
 
Hospital management system (php project) web engineering
Hospital management system (php project) web engineeringHospital management system (php project) web engineering
Hospital management system (php project) web engineering
 
Visiondocument
VisiondocumentVisiondocument
Visiondocument
 
WEB Based claim processing sytem SRS
WEB Based claim processing sytem SRSWEB Based claim processing sytem SRS
WEB Based claim processing sytem SRS
 
Report hospital
Report hospitalReport hospital
Report hospital
 
library management system
library management systemlibrary management system
library management system
 
EducationHub- Remote Education Website. Final defense presentation slide for ...
EducationHub- Remote Education Website. Final defense presentation slide for ...EducationHub- Remote Education Website. Final defense presentation slide for ...
EducationHub- Remote Education Website. Final defense presentation slide for ...
 
Software engineering srs library management assignment
Software engineering srs library management assignmentSoftware engineering srs library management assignment
Software engineering srs library management assignment
 
Library management system
Library management systemLibrary management system
Library management system
 
hospital management System
hospital management Systemhospital management System
hospital management System
 
DOCUMENTATION
DOCUMENTATIONDOCUMENTATION
DOCUMENTATION
 
Database versioning with liquibase
Database versioning with liquibaseDatabase versioning with liquibase
Database versioning with liquibase
 
Food Order Management System
Food Order Management SystemFood Order Management System
Food Order Management System
 
Database change management with Liquibase
Database change management with LiquibaseDatabase change management with Liquibase
Database change management with Liquibase
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 

Similar to Solution manual of shell programming assignment 2

The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docx
SUBHI7
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
kayalkarnan
 

Similar to Solution manual of shell programming assignment 2 (20)

Shell programming assignment 2
Shell programming assignment 2Shell programming assignment 2
Shell programming assignment 2
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
Shell programming
Shell programmingShell programming
Shell programming
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docx
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating systemShellProgramming and Script in operating system
ShellProgramming and Script in operating system
 
null Pune meet - Application Security: Code injection
null Pune meet - Application Security: Code injectionnull Pune meet - Application Security: Code injection
null Pune meet - Application Security: Code injection
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
 
Shell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdfShell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdf
 
The best unix shell scripting interview questions 2018 learn now!
The best unix shell scripting interview questions 2018   learn now!The best unix shell scripting interview questions 2018   learn now!
The best unix shell scripting interview questions 2018 learn now!
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Loops (Refined).pptx
Loops (Refined).pptxLoops (Refined).pptx
Loops (Refined).pptx
 
Unix lab
Unix labUnix lab
Unix lab
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell Variables
 
Slides
SlidesSlides
Slides
 
Powershell notes
Powershell notesPowershell notes
Powershell notes
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Php introduction
Php introductionPhp introduction
Php introduction
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 

More from Kuntal Bhowmick

More from Kuntal Bhowmick (20)

Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 6 -- inh...
Multiple Choice Questions on JAVA (object oriented programming) bank 6 -- inh...Multiple Choice Questions on JAVA (object oriented programming) bank 6 -- inh...
Multiple Choice Questions on JAVA (object oriented programming) bank 6 -- inh...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loopsMultiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
 
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- cla...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...
Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...
Multiple Choice Questions on JAVA (object oriented programming) bank 2 -- bas...
 
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
1. introduction to E-commerce
1. introduction to E-commerce1. introduction to E-commerce
1. introduction to E-commerce
 
Computer graphics question for exam solved
Computer graphics question for exam solvedComputer graphics question for exam solved
Computer graphics question for exam solved
 
DBMS and Rdbms fundamental concepts
DBMS and Rdbms fundamental conceptsDBMS and Rdbms fundamental concepts
DBMS and Rdbms fundamental concepts
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
Operating system Interview Questions
Operating system Interview QuestionsOperating system Interview Questions
Operating system Interview Questions
 
Computer Network Interview Questions
Computer Network Interview QuestionsComputer Network Interview Questions
Computer Network Interview Questions
 
C interview questions
C interview  questionsC interview  questions
C interview questions
 
C question
C questionC question
C question
 
Distributed operating systems cs704 a class test
Distributed operating systems cs704 a class testDistributed operating systems cs704 a class test
Distributed operating systems cs704 a class test
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Solution manual of shell programming assignment 2

  • 1. 1 Solution manual of Shell programming Assignment – 2 1. Write a Shell Script to find the reverse of a given number Using WC. Shell Script Output 2. Write a Shell Script to generate Fibonacci Series. Shell Script Output 3. Write a Shell Script to display Mathematical Table for a given number Shell Script
  • 2. 2 Output 4. Write a Shell Script to copy the content of a file to another file. Shell Script Output
  • 3. 3 5. Write a Shell Script to count the number of Vowels, Number of Consonants and Number of digits present in a given String. Shell Script Output
  • 4. 4 6. Write a Shell Script to accept file name & convert its contents from lower to upper case. Shell Script Output 7. Write a shell script that will receive a name interactively from the user during execution and prints a welcome message.(Say Hello <entered name>.Welcome to CSE Dept., Kalyani Govt. Engg. College !). Shell Script Output 8. Write a shell script that will receive a name interactively from the user during execution and prints greetings according to the system time. (Example: say user enters “Anirban” and if the system is less than 12.00 AM then the script will print : “Good Morning Anirban” else if the system time is greater than 12.00 AM but less than 6.00 PM then prints “Good After Noon Anirban” else if the system time is greater than 6.00 PM but less than 8.00 PM then “Good Evening Anirban” else if the system time is greater than 8.00 PM but less than 12.00 PM then “Good Night Anirban”).
  • 5. 5 Shell Script Output 9. Write a shell script that will receive a text filename(which contents a paragraph) interactively from the user during execution and prints the following according to the number of words present in the file: SHORT FILE(if the number of words is less than 100), MEDIUM FILE(if the number of words is greater than 100 but less than 350) , LARGE FILE( words greater than 350 but less than 500) and VERY LARGE FILE(words greater than 500). Shell Script
  • 6. 6 Output 10.Write a shell script that will receive a text filename as input and prints OFFICIAL FILE if the first line of the file contains the string “KGEC” only else prints UNOFFICIAL FILE. If the file is an OFFICIAL FILE then the program will prints number of words and characters present in the first 10 lines, it also appends string “Accessed on: <current date-time stamp>” at the end of the file. Shell Script Output 11.Write a shell script (check_exam.sh) that will use a file “exam_schedule.txt” to check whether there is any exam today or not. If there is no exam today then it will print: NO
  • 7. 7 EXAM TODAY. The file “exam_schedule.txt” must contain three fields as EXAM DATE(dd/mm/yyyy), EXAM TIME and EXAM PAPER. For example: 03/02/2014 10.00AM OPTICAL_NETWORK 04/02/2014 10.00AM IMAGE_PROCESSING ……… ……….. …………….. Shell Script Output 12.Write a shell script that will take the basic salary (BS) as runtime input from the user and calculates the DA (5% if BS is less than or equal to 10,000, above 10,000 it becomes 15%), HRA(5% if BS is less than or equal to 10,000, above 10,000 it becomes 7%) and finally calculates the gross salary(gross salary=BS+DA+HRA).
  • 8. 8 Shell Script Output 13.Write a shell script to display the following menu: i. Length of the string ii. Reverse of the string iii. Copy one string to another. Shell Script echo "Enter a string: " read str echo "i. Length of string" echo "ii.Reverse of the string" echo "iii. copy one string into another." echo "Enter your choice: " read c case "$c" in i)x=`echo $str | wc -c` x=`expr $x - 1` echo "Length is : $x";; ii)x=`echo $str | wc -c` x=`expr $x - 1` while [ $x -gt 0 ] do c=`echo $str | cut -c $x` s=$s$c x=`expr $x - 1` done echo "The Reverse of string is : $s";; iii)s=$str echo "The copied string is : $s";; esac
  • 9. 9 Output 14.Write a shell script to check whether a given number is prime or not. Shell Script echo "Enter a number: " read num i=2 f=0 while [ $i -le `expr $num / 2` ] do if [ `expr $num % $i` -eq 0 ] then f=1 fi i=`expr $i + 1` done if [ $f -eq 1 ] then echo "The number is composite" else echo "The number is Prime" fi Output 15.Write a shell script to check whether a given number is an Armstrong number or not. Shell Script echo "Enter a number: " read c x=$c sum=0 r=0 n=0 while [ $x -gt 0 ] do r=`expr $x % 10` n=`expr $r * $r * $r` sum=`expr $sum + $n` x=`expr $x / 10` done if [ $sum -eq $c ] then echo "It is an Armstrong Number."
  • 10. 10 else echo "It is not an Armstrong Number." fi Output 16.Write a shell script to find the sum of the first n numbers. Shell Script echo "Enter a number: " read num i=1 sum=0 while [ $i -le $num ] do sum=`expr $sum + $i` i=`expr $i + 1` done echo "The sum of first $num numbers is: $sum" Output 17.Write a shell script to find a sum of given no and to check out to see if it is even or odd. Shell Script echo "Enter a number: " read n sum=0 x=$n r=0 while [ $x -gt 0 ] do r=`expr $x % 10` sum=`expr $sum + $r` x=`expr $x / 10` done if [ `expr $sum % 2` -eq 0 ] then echo "The sum of $n is $sum and it is even" else echo "The sum of $n is $sum and it is odd" fi
  • 11. 11 Output 18.Write a shell script to find a factorial of a given number. Shell Script fact=1 ie=1 echo -e "Enter a number:c" read a while [ $ie -le $a ] do fact=`expr $fact * $ie` ie=`expr $ie + 1` done echo -e "Multilpication of $a number is $fact." Output 19.Write a shell script that takes 2 numbers through K/B and finds the value of first number raised to the power of second. Shell Script echo "Enter a number: " read a echo "Enter Power: " read p i=1 ans=1 while [ $i -le $p ] do ans=`expr $ans * $a` i=`expr $i + 1` done echo "Answer of $a^$p is $ans" Output 20.Write a shell script to read a string through keyboard and check whether it is palindrome or not. Shell Script echo "Enter a string: "
  • 12. 12 read s len=`echo $s | wc -c` while [ $len -gt 0 ] do st=`echo $s | cut -c $len` str=$str$st len=`expr $len - 1` done if [ $str = $s ] then echo "String Palindrome" else echo "string is not palindrome" fi Output