SlideShare una empresa de Scribd logo
1 de 8
Program 1

WAP to concatenate the contents of 2 files ?

cat > first
hai this is first file
^d

cat > second
hai this is Second file
^d

program
-------

vi prog1
echo contents of first file
cat first
echo contents of second file
cat second
echo contents of third file
cat first second > third
cat third
esc : x



output
------

sh prog1

Program 2
WAP to Find SUm,AVG,PRODUCT of 4 numbers ?

vi prog2
clear
echo enter A,B,C,D values

read a
read b
read c
read d

sum= `Expr $a + $b + $c + $d`
Avg= `Expr $sum /4`
Product= `Expr $a * $b * $c *d`

echo Sum is $sum
echo Avg is $Avg
echo Product is $ Product

esc:x

output
------

sh prog2

Program 3
WAP to change two values with out using another variable ?

vi prog3
clear
echo enter A,B values

read a
read b

echo actual values are A="$a" and B="$b"

a=`Expr $a + $b`
b=`Expr $a - $b`
c=`Expr $a - $b`

echo swapped values are "A"=$a and "B"=$b

esc:x

output
-----
sh prog3

Program 4
WAP to find largest of 3 numbers

vi prog4
clear
read a
read b
read c
if [$a -gt $b]

then

if [$a -gt $c]
then echo $a is Bigger
else
echo $c is Bigger
fi

else
if [$b -gt $c]
then
echo $b is Bigger
else
echo $c is Bigger
fi

fi

output
------
sh prog4

Program 5
WAp to find the Factorial of a given number

vi prog5
clear
echo enter the number to get Factorial

read n
fact=1
i=$n

while [$n -ge 1]
do
fact =`Expr $fact * $n`
n=`Expr $n-1`
done

echo Factorial of $i is $fact

output
------

sh prog5

Program 6
WAP to find the Sum of INDIVIDUAL digits of given numbers

vi prog6
clear

echo enter any number having atleast 2 digits

read n
i=$n
r=0
sum=0

while test $n -gt 0
do
r=`Expr $n %10`
sum=`Expr $sum + $r`
n=`Expr $n/10`
done
echo sum of individual digits of $i is $sum

output
-------

sh prog6

Program 7
WAP to find the reverse of a given number

vi prog7
clear
echo enter a number

read n
m=$n
x=0

while test $n -gt 0
do
r=`Expr $n %10`
x=`Expr $n *10 + $r`
n=`Expr $n/10`
done

echo reverse of given number is $x

output
------
sh prog7

Program 8
WAP to generate fibnacci series

vi prog8
clear
echo enter any number

read n
fo=0
f1=1

echo $fo
echo $f1
i=3

while test $i le $n
do
f2=`Expr $fo + $f1`
echo $f2
f0=$f1
f1=$f2
i=`Expr $i+1`
done

output
------
sh prog8

Program 9
WAP to check whether a given number is PALLENDROME or NOT

vi prog9
echo enter any number

read n
x=0
m=$n

while test $n -gt 0
do
r=`Expr $n%10`
x=`Expr $x *10 +r`
n=`Expr $n/10`
done

if test $x -eq $n
then
echo given number is PALLENDROME
else
echo given number is NOT a PALLENDROME
fi

output
------
sh prog9

Program 10
Write a menu Driven Prog

vi prog10

clear
echo "1.Contents of a FILE "
echo
echo "2.Present Working Directory"
echo
echo "3.EXIT"
echo
echo "Enter your Choice"
read ch

case $ch in
1)echo enter file name
read filename
cat $filename
;;
2)echo present working directory
pwd
;;
3)echo program EXIT
;;
*)echo Incorrect choice
;;
esac

output
-------
sh prog10

Program 11
WAP to count the no.of UPPER case letters , no.of lowercase letters, no.of digits
and no.of DIGITS and no.of Special characters in a given string

vi prog11
clear
echo enter a string

read s
len=`echo $s |wc-c`
h=`echo $len -1`
echo length is $h

u=0
l=0
d=0
sc=0

while test $n -gt 0
do
a=`echo $s |cat-c $n`
case $a in

[a-z])
l=`Expr $l+1`
;;

[A-Z])
u=`Expr $u+1`
;;

[0-9])
d=`Expr $d+1`
;;

*)
sc=`Expr $sc+1`
;;
esac
n=`Expr $n-1`
done

echo no.of uppercase letters are $u
echo no.of lowercase letters are $l
echo no.of digits are $d
echo no.of special characters are $sc

Más contenido relacionado

La actualidad más candente

เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™Boom Baphomet
 
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)HamHam' Kc
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd StudyChris Ohk
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2Rumman Ansari
 
Let's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distributionLet's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distributionMasahito Zembutsu
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programmingPrabhu Govind
 

La actualidad más candente (19)

Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Ps installedsoftware
Ps installedsoftwarePs installedsoftware
Ps installedsoftware
 
8.1
8.18.1
8.1
 
Factorial
FactorialFactorial
Factorial
 
Phpbase
PhpbasePhpbase
Phpbase
 
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
 
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
11 1 포인터
11 1 포인터11 1 포인터
11 1 포인터
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
Fork handout
Fork handoutFork handout
Fork handout
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2
 
Let's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distributionLet's begin resource monitoring with munin 2011 1209 zem_distribution
Let's begin resource monitoring with munin 2011 1209 zem_distribution
 
week-6x
week-6xweek-6x
week-6x
 
To connect two jframe
To connect two jframeTo connect two jframe
To connect two jframe
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
 
Hop ngu MIP
Hop ngu MIPHop ngu MIP
Hop ngu MIP
 

Destacado

Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
Unix Shell Scripting Tutorial | Unix Shell Scripting Online Training
Unix Shell Scripting Tutorial | Unix Shell Scripting Online TrainingUnix Shell Scripting Tutorial | Unix Shell Scripting Online Training
Unix Shell Scripting Tutorial | Unix Shell Scripting Online TrainingVyshnavi Reddy
 
Unix shell program training
Unix shell program trainingUnix shell program training
Unix shell program trainingAditya Sharat
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014Supriya Radhakrishna
 
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSM.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSSupriya Radhakrishna
 

Destacado (10)

Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
Unix1
Unix1Unix1
Unix1
 
Prog i
Prog iProg i
Prog i
 
Chap06
Chap06Chap06
Chap06
 
Unix Shell Scripting Tutorial | Unix Shell Scripting Online Training
Unix Shell Scripting Tutorial | Unix Shell Scripting Online TrainingUnix Shell Scripting Tutorial | Unix Shell Scripting Online Training
Unix Shell Scripting Tutorial | Unix Shell Scripting Online Training
 
Unix shell program training
Unix shell program trainingUnix shell program training
Unix shell program training
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Adbms lab manual
Adbms lab manualAdbms lab manual
Adbms lab manual
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
 
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSM.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
 

Similar a basic shell_programs

Similar a basic shell_programs (20)

32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
 
Richard practica nº2.php
Richard  practica nº2.phpRichard  practica nº2.php
Richard practica nº2.php
 
Richard practica nº2.php
Richard  practica nº2.phpRichard  practica nº2.php
Richard practica nº2.php
 
C important questions
C important questionsC important questions
C important questions
 
C code examples
C code examplesC code examples
C code examples
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
Paexec -- distributed tasks over network or cpus
Paexec -- distributed tasks over network or cpusPaexec -- distributed tasks over network or cpus
Paexec -- distributed tasks over network or cpus
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
SL-2.pptx
SL-2.pptxSL-2.pptx
SL-2.pptx
 
Data Types Master
Data Types MasterData Types Master
Data Types Master
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with Perl
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
C programs
C programsC programs
C programs
 
program in c
program in cprogram in c
program in c
 

Último

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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.pdfAdmir Softic
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
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...christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
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).pptxVishalSingh1417
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 

Último (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
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
 
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...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 

basic shell_programs

  • 1. Program 1 WAP to concatenate the contents of 2 files ? cat > first hai this is first file ^d cat > second hai this is Second file ^d program ------- vi prog1 echo contents of first file cat first echo contents of second file cat second echo contents of third file cat first second > third cat third esc : x output ------ sh prog1 Program 2 WAP to Find SUm,AVG,PRODUCT of 4 numbers ? vi prog2 clear echo enter A,B,C,D values read a read b read c read d sum= `Expr $a + $b + $c + $d` Avg= `Expr $sum /4`
  • 2. Product= `Expr $a * $b * $c *d` echo Sum is $sum echo Avg is $Avg echo Product is $ Product esc:x output ------ sh prog2 Program 3 WAP to change two values with out using another variable ? vi prog3 clear echo enter A,B values read a read b echo actual values are A="$a" and B="$b" a=`Expr $a + $b` b=`Expr $a - $b` c=`Expr $a - $b` echo swapped values are "A"=$a and "B"=$b esc:x output ----- sh prog3 Program 4 WAP to find largest of 3 numbers vi prog4 clear read a read b read c
  • 3. if [$a -gt $b] then if [$a -gt $c] then echo $a is Bigger else echo $c is Bigger fi else if [$b -gt $c] then echo $b is Bigger else echo $c is Bigger fi fi output ------ sh prog4 Program 5 WAp to find the Factorial of a given number vi prog5 clear echo enter the number to get Factorial read n fact=1 i=$n while [$n -ge 1] do fact =`Expr $fact * $n` n=`Expr $n-1` done echo Factorial of $i is $fact output
  • 4. ------ sh prog5 Program 6 WAP to find the Sum of INDIVIDUAL digits of given numbers vi prog6 clear echo enter any number having atleast 2 digits read n i=$n r=0 sum=0 while test $n -gt 0 do r=`Expr $n %10` sum=`Expr $sum + $r` n=`Expr $n/10` done echo sum of individual digits of $i is $sum output ------- sh prog6 Program 7 WAP to find the reverse of a given number vi prog7 clear echo enter a number read n m=$n x=0 while test $n -gt 0 do r=`Expr $n %10` x=`Expr $n *10 + $r`
  • 5. n=`Expr $n/10` done echo reverse of given number is $x output ------ sh prog7 Program 8 WAP to generate fibnacci series vi prog8 clear echo enter any number read n fo=0 f1=1 echo $fo echo $f1 i=3 while test $i le $n do f2=`Expr $fo + $f1` echo $f2 f0=$f1 f1=$f2 i=`Expr $i+1` done output ------ sh prog8 Program 9 WAP to check whether a given number is PALLENDROME or NOT vi prog9 echo enter any number read n x=0
  • 6. m=$n while test $n -gt 0 do r=`Expr $n%10` x=`Expr $x *10 +r` n=`Expr $n/10` done if test $x -eq $n then echo given number is PALLENDROME else echo given number is NOT a PALLENDROME fi output ------ sh prog9 Program 10 Write a menu Driven Prog vi prog10 clear echo "1.Contents of a FILE " echo echo "2.Present Working Directory" echo echo "3.EXIT" echo echo "Enter your Choice" read ch case $ch in 1)echo enter file name read filename cat $filename ;; 2)echo present working directory pwd ;; 3)echo program EXIT ;;
  • 7. *)echo Incorrect choice ;; esac output ------- sh prog10 Program 11 WAP to count the no.of UPPER case letters , no.of lowercase letters, no.of digits and no.of DIGITS and no.of Special characters in a given string vi prog11 clear echo enter a string read s len=`echo $s |wc-c` h=`echo $len -1` echo length is $h u=0 l=0 d=0 sc=0 while test $n -gt 0 do a=`echo $s |cat-c $n` case $a in [a-z]) l=`Expr $l+1` ;; [A-Z]) u=`Expr $u+1` ;; [0-9]) d=`Expr $d+1` ;; *) sc=`Expr $sc+1`
  • 8. ;; esac n=`Expr $n-1` done echo no.of uppercase letters are $u echo no.of lowercase letters are $l echo no.of digits are $d echo no.of special characters are $sc