Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Instructions:
1. Attendance should be 80 %, otherwise you may be debarred from the lab.
2. Notesprovidedaremeantonlyforguidelines.Notessolelywillnotcoverthesyllabus.Read
prescribedbooks.
Note: Lab Test1 (20 Marks) is scheduled in week 13-18 Oct for all the batches. Syllabus
is shell scripting (lab4, lab5, lab6). Absence from Lab Test 1 will lead to 0 marks.
Question 1 Read shell_1.pdf.
Question 2.(i) Write following shell script, save it, execute it and note down the its
output:
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
Question 2.(ii)
a=0
while [ "$a" -lt 10 ]
# this is loop1
do
b="$a"
while [ "$b" -ge 0 ] # this is loop2
do
Question 2 (iii)
for (( i=1; i<=5; i++ ))
do
for (( j=1; j<=i;
do
echo -n "$i"
done
echo ""
j++ ))
done
Question 2 (iv)
echo "Stars"
for (( i=1; i<=5; i++ ))
do
for (( j=1; j<=i; j++ ))
do
echo -n " *"
done
echo ""
done
for (( i=5; i>=1; i-- ))
do
for (( j=1; j<=i; j++ ))
do
echo -n " *"
done
echo ""
done
(ii)
Write a shell script that computes the gross salary of a employee according to
the following rules:
a. If basic salary is < 1500 then HRA =10% of the basic and DA =90% of
the basic.
b. If basic salary is >=1500 then HRA =Rs500 and DA=98% of the basic
The basic salary is entered interactively through the key boar
(iii)
Design a script to find that given file name is a file or directory. The name
of the file should be taken as a command line argument.
(iv)
(v)
Question 5. (i) Write a script prime.sh to output all the possible prime numbers between
given range of number read through standard input.
(ii) Write a shell script Armstrongs to output all the possible Armstrong numbers
between given range of number read through standard input.(An Armstrong number of
three digits is an integer such that the sum of the cubes of its digits is equal to the number
itself.
For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 37
(iii) Write a script called extract.sh that does the following. Create alphabets.txt which
contains uppercase alphabets. Given two arguments n and m with n< m, it prints the
subsequence of the alphabet in alphabets.txt that correspond to base pairs n through m,
both included. For example,
$ ./extract 1 1
A
$ ./extract 1 10
ABCDEFGHIJ