Os Ptatical Solution
Os Ptatical Solution
VERSI
TY
BCA(
Semest
er:
IV)
Cour
se:
US04CBCA27
(
Oper
ati
ngSy
stems)
Jour
nal
Def
ini
ti
ons
Not
e:Def
ini
ti
onswhi
char
emar
kedbol
dar
etobeconsi
der
edf
orj
our
nal
li
st.
1. Wr
it
eashel
lscr
iptt
odi
spl
aysy
stem dat
einf
oll
owi
ngf
ormat
:
Todayi
sSept
ember242009
$dat
e"+%B%m %Y"
Todayi
sThur
sday
$dat
e“+%A”
Ti
mei
sinhh:
mm:
ssAM/
PM
$dat
e“+%T%P”
2. Wr
it
eashel
lscr
iptt
ocal
cul
atesum oft
wogi
vennumber
s.
pr
ogr
am_
2.sh
echo"
ent
ert
hev
alueofa"
r
eada
echo"
ent
ert
hev
alueofb"
r
eadb
s=$(
(a+b)
)
echo$s
3. Wr
it
eashel
lscr
iptt
oper
for
m addi
ti
on,
subt
ract
ion,
mul
ti
pli
cat
ionanddi
vi
sion
oper
ati
onsont
wogi
vennumber
s.
pr
ogr
am_
3.sh
echo"
Ent
erv
alueofa"
r
eadx
echo"
Ent
erv
alueofb"
r
eady
echo"
Sum =`
expr$x+$y
`"
echo"
Sub=`
expr$x-$y
`"
echo"
Mul
=`expr$x\
*$y
`"
echo"
Div=`
expr$x/$y
`"
4. Wr
it
eashel
lscr
iptt
ofi
ndmaxi
mum numberoutoft
wogi
vennumber
.
pr
ogr
am_
4.sh
echo"
Ent
erv
alueofa"
r
eadx
echo"
Ent
erv
alueofb"
r
eady
i
f[$a-
gt$b]
t
hen
echo"
aismax"
el
se
echo"
bismax"
f
i
5. Wr
it
eashel
lscr
iptt
ocheckwhet
hert
heent
erednumberi
soddorev
en.
pr
ogr
am_
5.sh
echo-
n"Ent
erv
alueofa"
r
eada
x=$(
($a%2)
)
i
f[$x-
eq0]
t
hen
echo"
aisev
en"
el
se
echo"
aisodd"
f
i
6. Wr
it
eashel
lscr
iptt
ocheckwhet
hert
heent
erednumberi
sposi
ti
ve,
negat
iveor
zer
o.
pr
ogr
am_
6.sh
echo-
n"Ent
erv
alueofa"
reada
i
f[$a- gt0]
then
echo"aisposi
ti
ve"
eli
f[$a-lt0]
then
echo"aisnegat
ive"
eli
f[$a-eq0]
then
echo"aisZero"
else
echo"other"
fi
7. Wr
it
eashel
lscr
iptt
ocal
cul
ateaddi
ti
onoff
ir
stnnat
ural
number
s.
pr
ogr
am_
7.sh
echo-
n"Ent
erv
alueofn"
r
eadn
i
=1
t
ot=0
whi
l
e[$i
-le$n]
do
echo$i
t
ot=$(
(tot+i
))
i
=$(
(i+1)
)
done
echo"
sum i
s"$t
ot
8. Wr
it
eashel
lscr
iptt
ofi
ndf
act
ori
alofgi
vennumber
.
pr
ogr
am_
8.sh
echo-
n"Ent
erv
alueofn"
readn
i
=1
f
act
=1
whi
l
e[$i
-le$n]
do
echo$i
fact
=$((
fact*i
))
i
=$((i+1))
done
echo"
facti
s"$f
act
9. Wr
it
eascr
iptt
oinputanumbert
hrought
hekey
boar
dandcal
cul
atet
hesum of
oddv
alueandev
env
aluedi
git
ssepar
atel
y.
pr
ogr
am_
9.sh
echo"
Ent
erVal
ueofa"
r
eada
odd=0
ev
en=0
i
=1
whi
l
e[$i-
le$a]
do
x=$(
($i
%2)
)
i
f[$x-
eq0]
t
hen
ev
en=$(
(ev
en+i
))
el
se
echo"
odd"
f
i
i
=$(
(i+1)
)
done
echo"
evensum i
s"$ev
en
10. Checkwhet
heri
nput
tednumberi
spr
imenumberornot
.Di
spl
ayappr
opr
iat
e
message.
pr
ogr
am_
10.
sh
number =53
i
=2
fl
ag=0
whi l
etest$i-
le`
expr$number/2`
do
i
ft est`
expr$number%$ì-
eq0
then
fl
ag=1
fi
i
=` expr$i+1`
donei ftest$f
lag-
eq1
then
echo" ThenumberisNotPr
ime"
else
echo" ThenumberisPr
ime"
fi
11. Wr
it
eashel
lscr
iptt
oinputi
ntegercodef
rom user
.Ifcodei
s1or2t
hendi
spl
ay.
pr
ogr
am_
11.
sh
cho-n"Ent
erv
alueofa"
reada
i
f[$a- eq1]
then
echo"selectcodeone"
eli
f[$a- eq2]
then
echo"selectcodetwo"
else
echo" sel
ectwrongcode"
fi
or
echo-
n"Ent
erv
alueofa"
reada
case$ain
[1])
echo"sel
ectcaseone"
;
[
2])echo"
sel
ectcaset
wo"
;
*
) echo"
wrongsel
ect
"
esac
12. appr
opr
iat
emessageel
sedi
spl
aymessage“
wrongcode”
.(Usecase-
-->esac)
pr
ogr
am_
12.
sh
echo"
ent
ert
hef
rui
tname"
r
eadFRUI
T
case$FRUI
Tin
"
appl
e")
echo"
Appl
epi
eisqui
tet
ast
y.";
;
"
banana"
)
echo"
Ili
kebanananutbr
ead.
";;
"
kiwi
")
echo"
NewZeal
andi
sfamousf
orki
wi.
";;
*
)echo"
wrongf
rui
t"
esac
13. Wr
it
eashel
lscr
iptt
oinputi
ntegercodef
rom user
.Ifent
eredcodei
sbet
ween1
t
o4t
hendi
spl
ayappr
opr
iat
emessageel
sedi
spl
aymessage“
wrongcode”
.
pr
ogr
am_
13.
sh
echo-
n"Ent
erv
alueofa"
r
eada
case$ai
n
[
1])
echo"
sel
ectcaseone"
;;
[
2])
echo"
sel
ectcaset
wo"
;;
[
3])
echo"
sel
ectcaset
hree"
;;
[
4])
echo"
sel
ectcasef
our"
;;
[
5])
echo"
sel
ectcasef
ive"
;;
[
6])echo"
sel
ectcasesi
x";
;
*
) echo"
wrongsel
ect
"
Esac
14. Wr
it
eashel
lscr
iptt
hatcr
eat
emenuasf
oll
ows.
1. Copysour
cef
il
etodest
inat
ion
2. Renamet
hespeci
fi
edf
il
e
3. Pr
intt
hecont
ent
soff
il
e
4. Changeper
missi
onofspeci
fi
edf
il
eto(
read,
wri
te)f
oral
luser
s.
5. Di
spl
aysi
zeofspeci
fi
edf
il
einnumberofchar
act
er(
byt
e).
6. Exi
t
Not
e:usecaseandr
eadappr
opr
iat
eval
ueonchoi
ce.
pr
ogr
am_
14.
sh
f
ors1i
n123456
do
echo"
1.Copysour
cef
il
etodest
inat
ion"
;
echo"
2.Renamet
hespeci
fi
edf
il
e";
echo"
3.Pr
intt
hecont
ent
soff
il
e";
echo"
4.Changeper
missi
onofspeci
fi
edf
il
eto(
read,
wri
te)f
oral
luser
s."
;
echo"
5.Di
spl
aysi
zeofspeci
fi
edf
il
einnumberofchar
act
er(
byt
e).
";
echo"
6.Exi
t"
;
echo"
sel
ecty
ouropt
ionf
orper
for
mimg"
r
eads
case$si
n
[
1]) echo"
1.Copysour
cef
il
etodest
inat
ion"
;
cppr
g1.
shpr
g3.
sh;
;
[
2]) echo"
2.Renamet
hespeci
fi
edf
il
e";
mvpr
g_2.
shpr
g_22.
sh;
;
[
3]) echo"
3.Pr
intt
hecont
ent
soff
il
e";
catpr
g5.
sh;
;
[
4]) echo"
4.Changeper
missi
onofspeci
fi
edf
il
eto(
read,
wri
te)f
oral
luser
s."
;
chmoda+r
wpr
g_2.
sh;
;
[
5]) echo"
5.Di
spl
aysi
zeofspeci
fi
edf
il
einnumberofchar
act
er(
byt
e).
";
wcpr
g10.
sh;
;
*
)
echo"
sel
ectwr
ongcodeexi
t";
;
esac
done
15. Wr
it
eashel
lscr
iptt
ocr
eat
eamenudr
ivenpr
ogr
am whi
chhasf
oll
owi
ngopt
ions:
1.Li
stofuser
swhohav
eloggedi
n
2.Pr
esentwor
kingdi
rect
ory
3.Exi
t
pr
ogr
am_
15.
sh
echo"
1.Li
stofuser
swhohav
eloggedi
n"
echo"
2.Pr
esentwor
kingdi
rect
ory
"
echo"
3.Exi
t"
echo"
sel
ecty
ourchoi
ce"
r
eads
case$si
n
[
1])echo"
1.Li
stofuser
swhohav
eloggedi
n"
who;
;
[
2])echo"
2.Pr
esentwor
kingdi
rect
ory
"
pwd;
;
*
)echo"
3.Exi
t"
;
esac
16. Wr
it
eashel
lscr
iptt
hatr
emov
esal
lthef
il
esoft
hecur
rentdi
rect
oryhav
inggi
ven
ext
ensi
ons.
pr
ogr
am_
16.
sh
echo“ent
ert
heexpensi
on”
r
eadx;
r
m $x
echo“
rm commandr
unsuccessf
ull
y”
17. Wr
it
eashel
lscr
iptt
oli
stal
lthef
il
esoft
hecur
rentdi
rect
orywhi
chhav
ereadand
wr
it
eper
missi
onf
orot
her
s.
pr
ogr
am_
17.
sh
echo”l
istal
lfi
lesincurrentdi
rect
ory
”
l
s;
echo”changetheper mi
ssionread/wri
tet
oot
her”
chmodo+r w**.sh;
echo”commandr unsuccessful
l
y”
18. Wr
it
eashel
lscr
iptt
odi
spl
ayl
i
stofonl
yfi
l
esofcur
rentdi
rect
ory
.
$l
s
19. Wr
it
eashel
lscr
iptt
odi
spl
ayl
i
stofonl
ydi
rect
ori
esofcur
rentdi
rect
ory
.
$di
r
20. Wr
it
eashel
lscr
iptt
ocr
eat
eamenudr
ivenpr
ogr
am whi
chhasf
oll
owi
ngopt
ions:
pr
ogr
am_
20.
sh
1. Ls
2. Who
3. Pwd
echo"
1.Ls"
;
echo"
2.Who"
;
echo"
3.Pwd"
;
echo"
sel
ecty
ouchoi
ce"
;
r
eadr
case$ri
n
[
1])echo"
1.Ls"
;
l
s;
;
[
2])echo"
2.Who"
;
who;
;
[
3])echo"
3.Pwd"
;
pwd;
;
*
)echo"
3.Exi
t"
;
Esac
21. Cr
eat
eadat
afi
l
e“comput
er.
lst
”wi
thf
oll
owi
ngdat
a:
comput
er.
sh
di
skdr
ive
memor
y
v
ideomemor
y
moni
ter
t
apedr
ive
CD-
ROM
modem
moni
tor
soundl
ast
er
Not
e:-Fi
rsty
ouhav
ecr
eat
ecomput
erf
il
enamecomput
er.
sht
henper
for
mingt
his
al
lcommand.
Per
for
mfol
l
owi
ngoper
ati
onondat
afi
l
e“comput
er.
sh”
.
1. Sor
tthef
il
einascendi
ngor
der
.
sor
tcomput
er.
sh
2. Sor
tthef
il
eindescendi
ngor
der
.
sor
t–rcomput
er.
sh
3. Sor
tthef
il
ebyi
gnor
ingcase.
sor
t–ucomput
er.
sh
4. Sor
tthef
il
ebyav
oidi
ngdupl
i
cat
ion(
uni
quer
ecor
ds)
St
ep1:
-cat-
ncompu.sh
St
ep:
-2uniqcomput
er.
shcom.
sh
St
ep:
-3cat-ncom.
sh
5. Countnumberofwor
ds
wccomput
er.
sh
out
put:
-101284comput
er.
sh
6 Pr
intl
i
stnumberi
ngi
vencommand
cat-
ncompu.
sh