Vous êtes sur la page 1sur 28

SHELLPROGRAMS

USINGCOMMANDS
Writeaprogramtogetthenameandregnoandwhocommandtodisplaytheusers
logintime

#Thisistheexampleforshellscripting
echoe"\nEntertheNameandReg.no==>\t"
readNameRegNo
echoe"YourNameis==>$Name\nyourRegisterNumberis==>$RegNo
\nason`date;who`"
Findthelinescontaininganumberinafile
EchoEnterfilename
Readfilename
Grep[09]$filename
Writeaprogramtodisplaythelistofuserscurrentlyworkingandtotal.
clear
s=`who`
t=`who|wcl`
echoe"thenumberofuserscurrentlyworkingon\n$s"
echo"totalnumberofusers$t"
Writeashellscriptprogramtoconvertallthecontentinafileintouppercase.

(or)

clear
echo"enterthefilename"
readfile
tr'[:lower:]''[:upper:]'<$file
exit
EchoEnterthefilename
Readfilename
EchoContentsof$filenamebeforeconvertingtouppercase
Echo
cat$filename
Echo
EchoContentsof$filenameafterconvertingtouppercase
Echo
tr'[az]''[AZ]'<$filename

Echo
USINGCOMMANDLINEARGUMENTS
WriteashellScriptthatdemos,commandlinearguments
echo"Totalnumberofcommandlineargumentare$#"
echo"$0isscriptname"
echo"$1isfirstargument"
echo"$2issecondargument"
echo"Allofthemare:$*or$@"
WriteashellScriptwhichreceivestwofilesnamesasaarguments.Itshouldcheck
whetherthetwofilescontentsaresameornot.Iftheyaresamethenremovesecond
file.

if(cmp$1$2)
then
echo"thetwofilesareidentical"
rm$2
echo"Now$2isdeleted"
else
echo"thetwofilesaredifferent"
fi

Writeashellscripttocheckwhetheragivenuserisloggedinornot.
if(who|grep"^$1")
then
echo"the$1isloggedin"
else
echo"the$1isnotloggedin"
fi
WriteaProgramtoopentxtfilebyusingcatcommand
forvarin$(catfruit)
do
printf"$var\n"
done
Writeashellscripttofindtheaverageofthenumbersenteredincommandline
n=$#

sum=0
foriin$*
do
sum=`expr$sum+$i`
done
avg=`expr$sum/$n`
EchoAverage=$avg
USINGPRINTINGSTATEMENT
Writeashellscripttoaskyourname,programnameandenrollmentnumberand
printitonthescreen.
echoEnteryourname:
readName
echoEnteryourprogramname:
readProg
echoEnteryourenrollmentnumber:
readEnroll
Clear
echoDetailsyouentered
echoName:$Name
echoProgramName:$Prog
echoEnrolmentNumber:$Enroll
USINGSTRINGSTATEMENT
Writeashellprogramtoconcatenatethecontentsof2files
EchoEnterfirstfilename
Readfirst
EchoEntersecondfilename
Readsecond
cat$first>third
cat$second>>third
EchoAfterconcatenationofcontentsofenteredtwofiles
Echo
catthird|more
Echo
Writeashellscriptprogramtoconcatenatetwofilecontentandfindthelengthof
theresultantstring.
clear
echo"Entertwofiles"

readstr1
readstr2
str3=`cat$str1$str2|teefile1`
echo"$str3"
str4=`wc$str1$str2`
echo"$str4"
exit
Writeashellscriptprogramtoconcatenatetwostringsandfindthelength
clear
echo"Entertwostrings"
readstring1
readstring2
con=`echo"$string1$string2"`
echo"$con"
n=`echo$con|wcc`
count=`expr$n1`
echo"Thenumberofcharacteris=$count"
exit
Writeashellprogramtocountthecharacters,linesandwordsinafile.

(or)

clear
echo"Enterafile"
readfile
lines=`wcl<$file`
words=`wcw<$file`
c=`wcc<$file`
character=`expr$c1`
echoNooflines=$lines
echoNoofwords=$words
echoNoofcharacter=$character
exit
EchoEnterthefilename
Readfile
w=`cat$file|wcw`
c=`cat$file|wcc`
l=`grepc"."$file`
EchoNumberofcharactersin$fileis$c
EchoNumberofwordsin$fileis$w
EchoNumberoflinesin$fileis$l

Writeashellscripttoperformthefollowingstringoperationtoextractasubstring

fromagivenstringandtofindthelengthofthegivenstringusingswitchcase.
echo"MENU"
echo"1.TOEXTRACTASUBSTRINGFROMAGIVENSTRING"
echo"2.TOFINDTHELENGTHOFTHESTRING"
echo"ENTERYOURCHOICE"
readchoice
echo"enterastring"
readstring
case$choicein
1)echo"enterposition1"
readpos1
echo"enterposition2"
readpos2
echo"theextractedsubstringfrom$pos1to$pos2of$stringis"
echo$string|cutc$pos1$pos2;;
2)echothelengthofthestring$stringis
c=$(echo$string|wcc)
((ch=c1))
echo$chnumberofcharacters;;
*)echo"wrongchoice";;
esac
Writeaninteractiveshellscriptthatasksforawordandfilenameandthentells
howmanytimesthatwordoccurredinthefile.
clear
ch=0

while[$cheq0]
do
echo"enterwordandfilename"
readwordfile
iftestf$file
then
count=`cat$file|grepc$word`
echo"found$counttimes"
else
echo"$filedoesntexist"
fi
echo"anymore?(0yes,1no)"
readch

done
Writeashellscriptprogramtofindthepositionofsubstringinagivenstring.

echo"Enterthelengthofthemainstring"
reada
echo"Enterthemainstring"
for((i=1;i<=a;i++))
do
readx[i]
done
echo"Enterthelengthofthesubstring"
readb
echo"Enterthesubstring"
for((i=1;i<=b;i++))
do
ready[i]
done
for((i=1;i<=a;i++))
do
for((j=1;j<=b;j++))
do
if[${x[i]}=${y[j]}]
then
echo$i
fi
done
done
Writeashellscriptprogramtofindthenumberofvowelsinagivenstring.
clear
echo"EntertheString"
readstr
n=`echo$str|wcc`
n=`expr$n1`
index=1
count=0
while[$indexle$n]
do
c1=`echo$str|cutc$index`
echo$c1
if["$c1"=ao"$c1"=eo"$c1"=io"$c1"=oo"$c1"=u]
then
count=`expr$count+1`
fi
index=`expr$index+1`
done
echo$count

Writeashellscriptprogramtocheckwhetherthegivenstringispalindromeornot.
clear
index=0
count=1
tag=0
echo"EntertheStringforChecking"
readstr
s=`echo$str|wcc`
s=`expr$s1`
echo"Thenumberis$s"
s1=`expr$s/2`
echo$count
echo$s
while[$countle$s1]
do
c1=`echo$str|cutc$count`
c2=`echo$str|cutc$s`
echo"Thec1is$c1"
echo"Thec2is$c2"
if[$c1!=$c2]
then
tag=1
echo"ThegivennumberisnotaPalindrome"
break
fi
count=`expr$count+1`
s=`expr$s1`
done
if[$tageq0]
then
echo"ThegivennumberisaPalindrome"
fi
Write a shell program to count number of words, characters, white spaces and
specialsymbolsinagiventext
echoEnteratext
readtext
w=`echo$text|wcw`
w=`expr$w`
c=`echo$text|wcc`
c=`expr$c1`
s=0

alpha=0
j=``
n=1
while[$nle$c]
do
ch=`echo$text|cutc$n`
if[$ch=$j]
then
s=`expr$s+1`
fi
case$chin
(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)alpha=`expr$alpha+1`;;
esac
n=`expr$n+1`
done
special=`expr$c$s$alpha`
echoWords=$w
echoCharacters=$c
echoSpaces=$s
echoSpecialsymbols=$special

SIMPLEPROGRAMMESUSINGCOMMANDLINEARGUMENTS
Writeashellprogramtoadd,subtractandmultiplythe2givennumberspassedas
commandlinearguments
add=`expr$1+$2`
sub=`expr$1$2`
mul=`expr$1\*$2`
echoAdditionof$1and$2is$add
echoSubtractionof$2from$1is$sub
echoMultiplicationof$1and$2is$mul

SIMPLEPROGRAMMES
Writeashellscripttofindthesum,theaverageandtheproductofthefourintegers
entered
echoEnterfourintegerswithspacebetween
readabcd
Sum=`expr$a+$b+$c+$d`
Avg=`echo"scale=2;"$Sum/4|bc`
Dec=`echo"scale=2;"$Sum%4|bc`
Product=`expr$a\*$b\*$c\*$d`
echoSum=$Sum
echoAverage=$Avg
echoDec=$Dec
echoProduct=$Product
Writeashellscriptprogramtofindsimpleandcompoundinterest.
echo"Entervaluesofp,nandr"
readpnr
si=`echo$p\*$n\*$r/100|bc`
echo"SimpleInterest=Rs.$si"
c=`echo"scale=2;"$p\*\(1+$r/100\)^$n|bc`
ci=`echo"scale=2;"$c$p|bc`
echo"Compoundamount=Rs.$c"
echo"CompoundInterest=Rs.$ci"
Writeashellscriptprogramtoswaptwonumbers
echoEntervaluefora:
reada
echoEntervalueforb:

readb
echoValuesofvariablesbeforeswapping
echoA=$a
echoB=$b
echoValuesofvariablesafterswapping
a=`expr$a+$b`
b=`expr$a$b`
a=`expr$a$b`
echoA=$a
echoB=$b
Writeashellscriptprogramtofindthepowerofx
echo"Enterthevalueofxandn"
readxn
c=`echo$x^$n|bc`
echo$c

Writeashellprogramtocheckwhetheragivenyearisleapyearornot
readyr
c=`expr$yr%4`
if[$ceq0]
then
echo"yearisleap"
else
echo"notaleapyear"
fi
Writeaprogramtofindthequadraticequation
echo"Enterthecoefficentofx^2"
readabc
d=`echo"scale=3;($b*$b4*$a*$c)/2"|bc`
x1=`echo"scale=3;($b+$d)/2*$a"|bc`
x2=`echo"scale=3;($b$d)/2*$a"|bc`
echo$x1
echo$x2
USINGIFSTATEMENT
Writeashellscriptprogramtofindwhetherthegivennumberisoddoreven.
reada
if[$aeq0]

then
echo"thenumberisZero"
exit
fi
c=`expr$a%2`
echo$c
if[$ceq0]
then
echo"ThenumnerisEven"
else
echo"Thenumberisodd"
exit
fi
Write a shell script program to check whether the given number is positive or
negative
reads
if[$seq0]
then
echo"Thenumberisneitherpositiveornegative"
exit
fi
if[$sgt0]
then
echo"ThenumberisPositive"
else
echo"ThenumberisNegative"
fi
Writeashellscriptprogramtofindthesmallestandgreatestvalueamongthegiven
numbers.
echo"Enterthenumber"
readabc
if[$agt$ba$agt$c]
then
max=$a
else
if[$bgt$aa$bgt$c]
then
max=$b
else
max=$c
fi

fi
if[$ale$ba$ale$c]
then
min=$a
else
if[$ble$aa$ble$c]
then
min=$b
else
min=$c
fi
fi
echo$max
echo$min
Writeashellscriptprogramtocomputethegrosssalaryofaemployeeaccordingto
thefollowingrules.
a.Ifbasicsalaryis<1500thenhra=10%ofthebasicandda=90%ofthe
basic.
b.Ifbasicsalaryis>=1500thenhra=Rs500andda=98%ofthebasic.

clear
echo"EnterTheBasicSalary"
readbasic
if[$basiclt1500]
then
da=`expr$basic\*90/100`
hra=`expr$basic\*10/100`
else
da=`expr$basic\*98/100`
hra=500
fi
gross=`expr$basic+$da+$hra`
echo"Basic:$basic"
echo"DA:$da"
echo"HRA:$hra"
echo"Gross:$gross"
Writeashellscriptprogramtogetfivesubjectmarksandfindthegrade.
echo"Entermarksinfivesubjects"
readm1m2m3m4m5
per=`expr$m1+$m2+$m3+$m4+$m5/5`
if[$perge60]
then

echo"Firstdivision"
fi
if[$perge50a$perle59]
then
echo"Seconddivison"
fi
if[$perge40a$perle49]
then
echo"Thirddivison"
fi
if[$perle39]
then
echo"Fail"
fi
Writeashellscriptprogramtofindthequadraticequation

echo"entervalueofa,b,c"
readabc
if[$aeq0]
then
echo"invalid"
else
s=`expr$b\*$b4\*$a\*$c`
echo$s
if[$seq0]
then
x=`expr0$b/\(2\*$a\)`
echo$x$x
echo"rootsarerealandequal"
elif[$sgt0]
then
s1=`echosqrt\($s\)|bc`
echo$s1
x=`expr$b+$s1`
echo$x
xx=`expr2\*$a`
echo$xx
xe=`expr$x/$xx`
y=`expr$b$s1`
echo$y
ye=`expr$y/$xx`
echo"rootsarerealanddiff$xe$ye"
else
echo"rootsareimaginary"

fi
fi
USINGFORLOOP

Writeashellscriptprogramtodisplaythedigitswhichareinoddpositionina
givennumber.
echo"Enterthenumbers"
readn
for((i=0;n!=0;i++))
do
a=`expr$n%10`
t=`expr$i%2`
if[$teq0]
then
echo"$a"
fi
USINGWHILEDOSTATEMENT
Writeashellscriptprogramtofindthepowerofxusingwhilestatement
echo"Enterthevalueofx"
readx
echo"Enterthevalueofy"
ready
x1=1
a=1
while[$ale$y]
do
x1=`expr$x\*$x1`
a=`expr$a+1`
done
echo$x1
Writeashellscriptprogramtofindthesumofdigits.
echo"Enterthenumber"
reada
s=0
while[$agt0]
do
a1=`expr$a%10`
s=`expr$a1+$s`

a=`expr$a/10`
done
echo$s
WriteashellscriptprogramtogenerateFibonacciseries.
a=1
b=0
c=0
echo"Enterthedestinationnumber"
readno
echo$c
while[$clt$no]
do
c=`expr$a+$b`
echo$c
a=$b
b=$c
done
Writeashellprogramtoreversethedigitsoffivedigitinteger
echoEntera5digitnumber
readnum
n=$num
rev=0
while[$numne0]
do
r=`expr$num%10`
rev=`expr$rev\*10+$r`
num=`expr$num/10`
done
echoReverseof$nis$rev
Writeashellprogramtofindfactorialofgivennumber
echoEnteranumber
readn
fact=1
i=1
while[$ile$n]
do
fact=`expr$fact\*$i`
i=`expr$i+1`
done

echoFactorialof$nis$fact
Write a shell program to display the alternate digits in a given 7 digit number
startingfromthefirstdigit
EchoEntera7digitnumber
Readnum
n=1
while[$nle7]
do
a=`Echo$num|cutc$n`
Echo$a
n=`expr$n+2`
done
USINGWHILEANDIFSTATEMENTS
Writeashellscriptprogramtocheckwhetherthegivennumberisprimeornot.
a=2
readb
echo$b
while[$alt$b]
do
s=`expr$b%$a`
if[$seq0]
then
echo"Thenumberisnotprime"
exit
fi
a=`expr$a+1`
done
echo"ThenumberisPrime"
Writeashellprogramtofindthesumoftheseriessum=1+1/2+...+1/n
echoEnteranumber
readn
i=1
sum=0
while[$ile$n]
do
sum=`expr$sum+\(10000/$i\)`
i=`expr$i+1`
done

echoSumnseriesis
i=1
while[$ile5]
do
a=`echo$sum|cutc$i`
echoe"$a\c"
if[$ieq1]
then
echoe".\c"
fi
i=`expr$i+1`
done
Writeashellprogramtofindthegcdforthe2givennumbers
echoEntertwonumberswithspaceinbetween
readab
m=$a
if[$blt$m]
then
m=$b
fi
while[$mne0]
do
x=`expr$a%$m`
y=`expr$b%$m`
if[$xeq0a$yeq0]
then
echogcdof$aand$bis$m
break
fi
m=`expr$m1`
done
Writeashellscriptprogramtocheckwhetherthegivennumberispalindromeor
not.
echo"Enterthenumber"
reada
sum=0
b=$a
while[$bne0]
do
f=`expr$b%10`
sum=`expr$sum\*10+$f`

b=`expr$b/10`
done
if[$aeq$sum]
then
echo"ItsaPalindrome"
exit
else
echo"Itsnotapalindrome"
fi
WriteashellscriptprogramtogenerateArmstrongseriesuptogivennumber.
echo"Enterthenumber"
reada
for((i=1;i<=a;i++))
do
sum=0
r=$i
while[$rgt0]
do
b=`expr$r%10`
sum=`expr$sum+$b\*$b\*$b`
r=`expr$r/10`
done
if[$ieq$sum]
then
echoe"$sum\n"
fi
done
WriteaShellscripttofindoccurrenceofparticulardigitininputtednumber
Echon"enteranynumber:"
Readnumber
Echon"whichdigitnumberdouwanttocount:"
Readdigit
len=`echon$number|wcc`
Echo"thelengthofnumberis:$len"
count=0
whiletest$lengt0
do
flag=`Echon$number|cutc$len`
iftest$flageq$digit
then
count=`expr$count+1`

fi
len=`expr$len1`
done
Echo"|$digit|occurred|$count|timesinnumber($number)"
USINGARRAYVALUES
Writeashellscriptprogramtofindthesumofsquares.
echo"Enterthenumbers"
readn
for((i=0;i<n;i++))
do
reada[i]
done
sum=0
for((i=0;i<n;i++))
do
b[i]=`expr${a[i]}\*${a[i]}`
echoThesquareofthenumber${a[i]}is${b[i]}
sum=`expr$sum+${b[i]}`
done
echoThesumofsquaresis$sum
Writeashellscriptprogramtofindthestandarddeviation
echo"Enterthenumber"
readn
for((i=0;i<n;i++))
do
reada[i]
done
d=0
for((i=0;i<n;i++))
do
d=`echo$d+${a[i]}|bc`
done
avg=`echo$d/$n|bc`
sd=0
for((i=0;i<n;i++))
do
sd=`echo"scale=2;"${a[i]}$avg\*${a[i]}$avg+$sd|bc`
sd=`echo"scale=2;"$sd/2|bc`
done
echoavgis$avg

echosdis$sd
Writeashellscriptprogramtofindthesumandaverageusingarray.
echo"Entertheno.ofterms:"
readn
sum=0
for((i=1;i<=n;i++))
do
reada[i]
done
for((i=1;i<=n;i++))
do
sum=`expr$sum+${a[i]}`
done
avg=`expr"scale=4;$sum/$n"|bc`
echoThesumis:$sum
echoTheavgis:$avg
Writeashellscriptprogramtosortthevaluesinascendingorder.
echo"Entertheno.ofelements"
readn
echo"Entertheelements"
for((i=0;i<n;i++))
do
reada[i]
done
echo"Arraybeforesorting"
for((i=0;i<n;i++))
do
echo${a[i]}
done
for((i=0;i<n;i++))
do
for((j=i+1;j<n;j++))
do
if[${a[i]}gt${a[j]}]
then
temp=${a[i]}
a[i]=${a[j]}
a[j]=$temp
fi
done
done

echo"Ascendingorder"
for((i=0;i<n;i++))
do
echo"${a[i]}"
done
Writeashellscriptprogramtosortthevaluesindescendingorder
echo"Entertheno.ofelements"
readn
echo"Entertheelements"
for((i=0;i<n;i++))
do
reada[i]
done
echo"Arraybeforesorting"
for((i=0;i<n;i++))
do
echo${a[i]}
done
for((i=0;i<n;i++))
do
for((j=i+1;j<n;j++))
do
if[${a[i]}lt${a[j]}]
then
temp=${a[i]}
a[i]=${a[j]}
a[j]=$temp
fi
done
done
echo"DescendingOrder"
for((i=0;i<n;i++))
do
echo"${a[i]}"
done
USINGSWITCHCASESTATEMENT
Writeashellscriptprogramtodoarithmeticoperationusingswitchcase.
echo"Enterthenumber"
readab
echo"1.Addition"

echo"2.subtraction"
echo"3.multiplication"
echo"4.Division"
readch
case$chin
1)expr$a+$b;;
2)expr$a$b;;
3)expr$a\*$b;;
4)expr$a/$b;;
*)echo"Invalidentry";;
esac

Writeaprograminswitchcaseusingcommand
readopt
#opt=$?
case$optin
date/time)date;;
calendar)cal;;
editor)vi;;
esac
Write ashell script programto find date/time, list offiles in current directory,
calenderandvieditorusingswitchcase.
t=1
while["$t"eq1]
do
clear
echo""
echo"MainMenu"
echo""
echo"[1]ShowTodaysdate/time"
echo"[2]Showfilesincurrentdirectory"
echo"[3]Showcalendar"
echo"[4]Starteditortowriteletters"
echo"[5]Exit/stop"
echo"==================================="
echon"Enteryourmenuchoice[15]:"
readyourch
case$yourchin
1)echo"Todayis`date`,pressakey...";readt;;
2)echo"Filesin`pwd`";lsl;echo"pressakey...";readt;;
3)cal;echo"pressakey....";readt;;

4)vi;;
5)exit0;;
6)echo"Opps!!!Pleaseselectchoice1,2,3,4,or5";
echo"wanttodisplayanotherpayslip....press1else2";
readt
esac
done
Writeaprogramtoexecutewordcountbyusingcommandlineargument
if[$#eq1]
then
terminal=`tty`
exec<$1
flag=1
fi
nol=0
now=0
whilereadline
do
nol=`expr$nol+1`
set$line
now=`expr$now+$#`
done
echo"Numberoflines=$nol"
echo"Numberofwords=$now"
if[$flageq1]
then
exec<$terminal
fi
Writeaprogramtocalculaterandomnumbers
n=2
echo"$n"
while[$nlt100]
do
n=`expr$n+1`
echo"$n"
n=`expr$n1`
echo"$n"
n=`expr$n\*2`
done

Writeaprogramtoprintthearrayvalues
#arraydefinitionandinitialization
a=(12345678910)
b=(12345678910)
#printinganentirearray
echo${a[*]}
echo${b[*]}
Writeaprogramtoprintthegivenvaluesinfloatingpoint
var1=20
var2=3.14159
var3=`echo"scale=4;$var1*$var1"|bc`
var4=`echo"scale=4;$var3*$var2"|bc`
echothefinalresultis$var4
echo$var3
Writeaprogramtoprinttheincrementanddecrementvalueusingforloop

for((a=1,b=10;a<=10;a++,b))
do
echo"$a$b"
done
Writeaprogramtodisplaythevaluesdecreasingby25
var1=100
until[$var1eq0]
do
echo$var1
var1=$[$var125]
done
Writeaprogramtodisplaytheouterloopandinnerloop
for((a=1;a<4;a++))
do
echo"Outerloop:$a"
for((b=1;b<100;b++))
do
if[$beq5]
then
break
fi
echo"Innerloop:$b"

done
done

Writeaprogramtoprintthestatenameusingteststatement
fortestinAlabamaAlaskaArizonaArkasnsasCaliforniaColorado
do
echoThenextstateis$test
done
Writeaprogramtoprintthestatementgivenintheecho
forwordinHighonahillwasalovelymountain
do
echo$word
done
Writeaprogramtoprintthearrayvaluesadditionofaandb
a=(123456789)
b=(123456789)
for((i=0;i<9;i++))
do
c[i]=`expr${a[i]}+${b[i]}`
echoe"\t${c[i]}"
done
Writeaprograminswitchcasetoprintthestatement
echoEntereither1or2
readi
if[$ieq1]
then
echoyouwouldgotoheaven!
else
if[$ieq2]
then
echoHellwascreatedwithyouinmind
else
echoHowaboutmotherearth!
fi
fi
Writeashellscripttofindthelargestamongthe3givennumbers
EchoEnter3numberswithspacesinbetween

Readabc
1=$a
if[$bgt$l]
then
l=$b
fi
if[$cgt$l]
then
l=$c
fi
EchoLargestof$a$b$cis$l
Write a shell program to search for a given number from the list of numbers
providedusingbinarysearchmethod
EchoEnterarraylimit
Readlimit
EchoEnterelements
n=1
while[$nle$limit]
do
Readnum
evalarr$n=$num
n=`expr$n+1`
done
EchoEnterkeyelement
Readkey
low=1
high=$n
found=0
while[$foundeq0a$highgt$low]
do
mid=`expr\($low+$high\)/2`
evalt=\$arr$mid
if[$keyeq$t]
then
found=1
elif[$keylt$t]
then
high=`expr$mid1`
else
low=`expr$mid+1`
fi
done
if[$foundeq0]

then
EchoUnsuccessfulsearch
else
EchoSuccessfulsearch
fi
Writeashellscripttofindthesmallestofthreenumbers
EchoEnter3numberswithspacesinbetween
Readabc
s=$a
if[$blt$s]
then
s=$b
fi
if[$clt$s]
then
s=$c
fi
EchoSmallestof$a$b$cis$s

WriteashellscripttosortthegivennumbersindescendingorderusingBubblesort
Echo
i=1
k=1
Echo"Enterno.ofintegerstobesorted"
Readn
Echo"Enterthenumbers"
while[$ile$n]
do
Readnum
x[$k]=`expr$num`
i=`expr$i+1`
k=`expr$k+1`
done
x[$k]=0
k=1
Echo"Thenumberyouhaveenteredare"
while[${x[$k]}ne0]
do
Echo"${x[$k]}"
k=`expr$k+1`

done
k=1
while[$kle$n]
do
j=1
while[$jlt$n]
do
y=`expr$j+1`
if[${x[$j]}gt${x[$y]}]
then
temp=`expr${x[$j]}`
x[$j]=`expr${x[$y]}`
x[$y]=`expr$temp`
fi
j=`expr$j+1`
done
k=`expr$k+1`
done
k=1
Echo"Numberinsortedorder..."
while[${x[$k]}ne0]
do
Echo"${x[$k]}"
k=`expr$k+1`
done
WriteaShellScripttoreverseainputtedstringandshowit
Echon"enterthestringuwanttoreverse:"
Readstring
len=`Echon$string|wcc`
Echo"noofcharacteris:$len"
whiletest$lengt0
do
rev=$rev`Echo$string|cutc$len`
len=`expr$len1`
done
Echo"thereversestringis:$rev"

Vous aimerez peut-être aussi