)
Provide appropriate security options to these files.
(
h
)
List the contents of directory.
$vi prg36
(a) Pwd
(b) clear
(c) date
(d) mkdir d
cd d
mkdir d1
(e) cd d1
(f) touch file1 file2
(g) chmod 644 file1 file2
(h) Is
37. The marks obtained by a student in five different subjects are input through the keyboard. The student gets a division as per the following rules. (Using else’s clause).
if percentage greater than or equal to 60 get First division
if percentage greater than or equal to 50 or less than 60 get Second division
if percentage greater than or equal to 40 or less than 50 get Third division
if percentage less than 40 Fail
$vi prg37
clear
echo enter marks of five subjects (out of 100 each)
read m1
read m2
read m3
read m4
read m5
per=‘echo \( $m1 + $m2 + $m3 + $m4 + $m5 \) /5 | bc’
echo
echo Percentage is $per
if [ $per –ge 60 ]
then
echo First division
else
if [ $per –ge 50 –a -$per –lt 60 ]
then
echo Second division
else
if [ $per –ge 40 –a $per –lt 50 ]
then
echo Third division
else
echo Fail
fi
fi
fi
Sample Run
$sh prg37
enter marks of five subjects
44
67
80
90
67
Percentage is 69
First division
$sh prg37
enter marks of five subjects
56
54
53
51
60
Percentage is 54
Second division
$sh prg37
enter marks of five subjects
46
54
41
42
46
Percentage is 45
Third division
$sh prg37
enter marks of five subjects
34
42
31
32
23
Percentage is 32
Fail
38. The marks obtained by a student in two different subjects are input through the keyboard. The student gets a division as per the following rules. (Using elif clause).
if percentage greater than or equal to 60 get First division
if percentage greater than or equal to 50 or less than 60 get Second division
if percentage greater than or equal to 40 or less than 50 get Third division
if percentage less than 40 Fail
$vi prg38
clear
echo enter marks of five subjects
read m1
read m2
read m3
read m4
read m5
per=‘echo \( $m1 + $m2 + $m3 + $m4 + $m5 \) /5 | bc’
echo
echo Percentage is $per
if [ $per –ge 60 ]
then
echo First division
elif [ $per –ge 50 –a -$per –lt 60 ]
then
echo Second division
elif [ $per –ge 40 –a $per –lt 50 ]
then
echo Third division
else
echo Fail
fi
Sample Run
$sh prg38
enter marks of five subjects
44
67
80
90
67
Percentage is 69
First division
$sh prg38
enter marks of five subjects
56
54
53
51
60
Percentage is 54
Second division
$sh prg38
enter marks of five subjects
46
54
41
42
46
Percentage is 45
Third division
$sh prg38
enter marks of five subjects
34
42
31
32
23
Percentage is 32
Fail
39. Write a shell script to generate first ‘n’ terms of the following sequence without using multiplication-1 2 4 8 16 32…………n.
$vi prg39
clear
echo enter the value of n
read n
echo
i=1
while test $i –le $n
do
echo $i
i=‘expr $i + $i’
done
Sample Run
$sh p39
enter the value of n
20
1
2
4
8
16
40. Write a shell script to find greatest common divisor (GCD) for two given numbers.
$vi prg40
clear
echo enter numbers a and b
read a b
while [ 1 ] # infinite loop
do
c=‘expr $a % $b’
if [ $c -eq 0 ]
then
echo GCD = $b
exit
fi
a=$b
b=$c
done
Sample Run
$sh prg40
enter numbers a and b 47 3 GCD = 1
41. Write a shell script that takes as command-line input, a number n and a word. It then prints the word n times, one word per line.
$vi prg41
clear
i=1
while [ $i –le $1 ]
do
echo $2
i=‘expr $i + 1’
done
Sample Run
$sh prg41 5 Hello
Hello
Hello
Hello
Hello
Hello
42. Write a shell script to remove all words that occur more than once in a list.
$vi prg42
clear
echo enter list
cat >file1
echo uniques are :
sort –u file1>file1.out
cat file1.out
Sample Run
$sh prg42
enter list
a
c
a
b
c
Uniques are :
a
b
c
43. Write a shell script to take backup of all c files.
$vi prg43
clear
ls abc >a1
if test – a1
then
mkdir abc
cp *.c /abc
echo backup is done
fi
44. Write a program in UNIX to accept range of months and display calendar within that range.
$vi prg44
clear
echo enter lower limit
read llimit
echo enter upper limit
read ulimit
echo enter year
read y
echo
while test $llimit -le $ulimit
do
cal $llimit $y
llimit=‘expr $llimit + 1’
done
Sample Run
$sh prg44
enter lower limit
2
enter upper limit
3
enter year
2008
February 2008
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29
March 2008
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
45. Write a program in UNIX to accept a year and months in that year and display calendar of those months.
$vi prg45
clear
echo enter month value in numeric
read m
echo enter year
read y
echo
for i in $m
do
cal $i $y
done
Sample Run
$sh prg45
enter month value in numeric