Upcoming SlideShare
×

basic shell_programs

269 views

Published on

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
269
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
0
0
Likes
0
Embeds 0
No embeds

No notes for slide

basic shell_programs

1. 1. Program 1WAP to concatenate the contents of 2 files ?cat > firsthai this is first file^dcat > secondhai this is Second file^dprogram-------vi prog1echo contents of first filecat firstecho contents of second filecat secondecho contents of third filecat first second > thirdcat thirdesc : xoutput------sh prog1Program 2WAP to Find SUm,AVG,PRODUCT of 4 numbers ?vi prog2clearecho enter A,B,C,D valuesread aread bread cread dsum= `Expr \$a + \$b + \$c + \$d`Avg= `Expr \$sum /4`
2. 2. Product= `Expr \$a * \$b * \$c *d`echo Sum is \$sumecho Avg is \$Avgecho Product is \$ Productesc:xoutput------sh prog2Program 3WAP to change two values with out using another variable ?vi prog3clearecho enter A,B valuesread aread becho 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"=\$besc:xoutput-----sh prog3Program 4WAP to find largest of 3 numbersvi prog4clearread aread bread c
3. 3. if [\$a -gt \$b]thenif [\$a -gt \$c]then echo \$a is Biggerelseecho \$c is Biggerfielseif [\$b -gt \$c]thenecho \$b is Biggerelseecho \$c is Biggerfifioutput------sh prog4Program 5WAp to find the Factorial of a given numbervi prog5clearecho enter the number to get Factorialread nfact=1i=\$nwhile [\$n -ge 1]dofact =`Expr \$fact * \$n`n=`Expr \$n-1`doneecho Factorial of \$i is \$factoutput
4. 4. ------sh prog5Program 6WAP to find the Sum of INDIVIDUAL digits of given numbersvi prog6clearecho enter any number having atleast 2 digitsread ni=\$nr=0sum=0while test \$n -gt 0dor=`Expr \$n %10`sum=`Expr \$sum + \$r`n=`Expr \$n/10`doneecho sum of individual digits of \$i is \$sumoutput-------sh prog6Program 7WAP to find the reverse of a given numbervi prog7clearecho enter a numberread nm=\$nx=0while test \$n -gt 0dor=`Expr \$n %10`x=`Expr \$n *10 + \$r`
5. 5. n=`Expr \$n/10`doneecho reverse of given number is \$xoutput------sh prog7Program 8WAP to generate fibnacci seriesvi prog8clearecho enter any numberread nfo=0f1=1echo \$foecho \$f1i=3while test \$i le \$ndof2=`Expr \$fo + \$f1`echo \$f2f0=\$f1f1=\$f2i=`Expr \$i+1`doneoutput------sh prog8Program 9WAP to check whether a given number is PALLENDROME or NOTvi prog9echo enter any numberread nx=0
6. 6. m=\$nwhile test \$n -gt 0dor=`Expr \$n%10`x=`Expr \$x *10 +r`n=`Expr \$n/10`doneif test \$x -eq \$nthenecho given number is PALLENDROMEelseecho given number is NOT a PALLENDROMEfioutput------sh prog9Program 10Write a menu Driven Progvi prog10clearecho "1.Contents of a FILE "echoecho "2.Present Working Directory"echoecho "3.EXIT"echoecho "Enter your Choice"read chcase \$ch in1)echo enter file nameread filenamecat \$filename;;2)echo present working directorypwd;;3)echo program EXIT;;
7. 7. *)echo Incorrect choice;;esacoutput-------sh prog10Program 11WAP to count the no.of UPPER case letters , no.of lowercase letters, no.of digitsand no.of DIGITS and no.of Special characters in a given stringvi prog11clearecho enter a stringread slen=`echo \$s |wc-c`h=`echo \$len -1`echo length is \$hu=0l=0d=0sc=0while test \$n -gt 0doa=`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. 8. ;;esacn=`Expr \$n-1`doneecho no.of uppercase letters are \$uecho no.of lowercase letters are \$lecho no.of digits are \$decho no.of special characters are \$sc