0% found this document useful (0 votes)
15 views

Linux Practicals

Uploaded by

maulikdedunmmm
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)
15 views

Linux Practicals

Uploaded by

maulikdedunmmm
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/ 6

1.

Write a shell script to accept a message from the user and print it on the
screen.
2. Write a shell script to check whether a given number is positive, negative
or zero.
3. Write a shell script which 1) list the files 2) date of system 3) print the
current working directory 4) date in the format dd/mm/yy using "case
statement".
4. Write a shell script for find maximum number from three numbers.
5. Write a shell script for find minimum number from three numbers.
6. Write a shell script to implement menu-based calculator. (Operators: +, -,
*, /, %)
7. Write a script to check if the two strings are same or not.
8. Write a script to print n to 1 using while loop. Accept the value of n from
the user.
9. Write a script to print 1 to n using for loop. Accept the value of n from
the user.
10.Write a shell script to check whether a number is even or odd.
11.Write a shell script to read 2 numbers and check whether two numbers
are equal or not. Display appropriate message. If numbers are equal then
print addition otherwise print subtraction.
12.Write a shell script to find out whether the person is eligible for blood
donation. A person is eligible for blood donation if the person’s age is
above 20 and weight must be above 45kg.
13.Write a shell script to find out perimeter and area of square.
14.If cost price and selling price of an item is input through the keyboard,
write a program to determine whether the seller has made profit or
incurred loss. Also determine how much profit was made or loss incurred.
15.Write a script to accept a year as an input. Check whether it is a leap year
or not.

--------------------------------------Solution Set------------------------------------
1.
echo "Enter message"
read message
echo $message

----------
2.
echo "Enter number"
read number
if [ $number -gt 0 ];
then
echo "Number is positive"
elif [ $number -lt 0 ];
then
echo "Number is negative"
else
echo "Number is zero"
fi

----------
3.
echo "-----Menu------"
echo "1) list the files"
echo "2) date"
echo "3) print the current working directory"
echo "4) date in the format dd/mm/yy"
echo "Enter choice"
read choice
case $choice in
1) ls;;
2) date;;
3) pwd;;
4) date +"%d/%m/%y";;
*) echo "Invalid choice";;
esac

----------
4.
echo "Enter n1 n2 n3"
read n1 n2 n3
if [ $n1 -gt $n2 -a $n1 -gt $n3 ];
then
echo "Number 1 is the largest number"
elif [ $n2 -gt $n1 -a $n2 -gt $n3 ];
then
echo "Number 2 is the largest number"
else
echo "Number 3 is the largest number"
fi
----------
5.
echo "Enter n1 n2 n3"
read n1 n2 n3
if [ $n1 -lt $n2 -a $n1 -lt $n3 ];
then
echo "Number 1 is the smallest number"
elif [ $n2 -lt $n1 -a $n2 -lt $n3 ];
then
echo "Number 2 is the smallest number"
else
echo "Number 3 is the smallest number"
fi

echo "Enter two numbers"


read n1 n2
echo "-----Menu------"
echo "1) Addition"
echo "2) Subtraction"
echo "3) Division"
echo "4) Multiplication"
echo "5) Modulo"
echo "Enter choice"
read choice
case $choice in
1) sum=`expr $n1 + $n2`
echo $sum;;
2) sub=`expr $n1 - $n2`
echo $sub;;
3) div=`expr $n1 / $n2`
echo $div;;
4) mul=`expr $n1 \* $n2`
echo $mul;;
5) mod=`expr $n1 % $n2`
echo $mod;;
*) echo "Invalid choice";;
esac
----------
7.
echo "Enter string 1"
read s1
echo "Enter string 2"
read s2
if [ $s1 = $s2 ];
then
echo "Both the strings are same"
else
echo "Both the strings are different"
fi

----------
8.
echo "Enter n"
read n
i=$n
while [ $i -ge 1 ]
do
echo $i
i=`expr $i - 1`
done

----------
9.
echo "Enter n"
read n
for((i=1;i<=$n;i++))
do
echo $i
done

----------
10.
echo "Enter n"
read n
ans=`expr $n % 2`
if [ $ans -eq 0 ];
then
echo "Number is even"
else
echo "Number is odd"
fi

----------
11.
echo "Enter n1 n2"
read n1 n2
if [ $n1 -eq $n2 ];
then
sum=`expr $n1 + $n2`
echo $sum
else
sub=`expr $n1 - $n2`
echo $sub
fi

----------
12.
echo "Enter age"
read age
echo "Enter weight"
read weight
if [ $age -gt 20 -a $weight -gt 45 ];
then
echo "Eligible to vote"
else
echo "Not eligible to vote"
fi

----------
13.
echo "Enter length"
read length
area=`expr $length \* $length`
perimeter=`expr $length \* 4`
echo "Area of square is: "$area
echo "Perimeter of square is: "$perimeter

----------
14.
echo "Enter cost price"
read cp
echo "Enter selling price"
read sp
if [ $sp -gt $cp ];
then
profit=`expr $sp - $cp`
echo "Profit is: "$profit
else
loss=`expr $cp - $sp`
echo "Loss is: "$loss
fi

----------
15.
echo "Enter year"
read year
ans=`expr $year % 4`
if [ $ans -eq 0 ];
then
echo "Leap year"
else
echo "Not a leap year"
fi

You might also like