OS Lab4
OS Lab4
Question 1 : Write a shell script, which finds the prime factors of a given
number.
echo -n "Enter Number : " read n
(( i=2;i<=$n;i++)){
# do if [ $(($n % $i))
== 0 ] then flg=2
# echo "$flg"
# echo "$i"
# for j in `seq 2 $i` for
(( j=2;j<$i;j++)){
# do if [ $(($i %
$j)) == 0 ] then
flg=1 fi # done
} if [ $(($flg)) == 2 ]
then echo "$i" fi
fi
# done
}
Question 2 : Write a shell script that accepts a positive integer value from the
user, say 34, and prints out all the divisors of 34 as a list:
Enter a positive integer: 34
The divisors of 34 are: 1, 2, 17, and 34
fi }
Question 3 : Write a shell script, which prints good morning or good evening
depending on the login time of the user
h=`date +%H` if [ $h lt
12 ]; then echo Good
Morning elif [ $h
-lt 18 ]; then echo
Good Afternoon else
echo Good Evening fi
Question 4 : A shell script, which takes as command line input a number n,
and a word. It then prints the word n times, once on each line.
for((i=0;i<$n;i++));
do echo $word done
Question 5 : Write a shell script, which finds the total number of blank lines in
the given file.
grep -n ^$ five.txt