0% found this document useful (0 votes)
0 views4 pages

OS Lab4

The document contains a lab assignment with five questions related to shell scripting. It includes scripts for finding prime factors, printing divisors of a number, greeting based on time, printing a word multiple times, and counting blank lines in a file. Each question is accompanied by code snippets demonstrating the required functionality.

Uploaded by

Akshat Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

OS Lab4

The document contains a lab assignment with five questions related to shell scripting. It includes scripts for finding prime factors, printing divisors of a number, greeting based on time, printing a word multiple times, and counting blank lines in a file. Each question is accompanied by code snippets demonstrating the required functionality.

Uploaded by

Akshat Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

OS LAB ASSIGNMENT-4

Name : Akshat Sahu Addmission No : U22CS034

Question 1 : Write a shell script, which finds the prime factors of a given
number.
echo -n "Enter Number : " read n

# for i in `seq 2 $((n/2))` for

(( 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

echo -n "Enter Number : " read


n for (( i=1;i<=$n;i++)){
if [
$(($n % $i)) == 0 ] then echo
"$i"

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.

echo "Enter n and word:"


read n word

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

You might also like