Questions:
Write a shell script to add, subtract and multiply 2 given numbers by passing as command line argument.
Write a shell script to check whether the number is odd or even.
Write a shell script to check whether the number is positive or negative.
Write a shell script to find largest and smallest number among 3 numbers.
Write a shell script to accept name, roll no. and marks in 4 subject & calculate. The grade as per the following statement:
<50 —> F grade
=50 & <60 —> C grade
=60 & <70 —> B grade
=70 & <80 —> A grade
=80 & <90 —> E grade
=90 & <=100 —> O grade
Answers:
#!/bin/bash
a=$1
b=$2
sum=$(($a+$b))
diff=$(($a-$b))
prod=$(($a*$b))
echo "Sum: $sum"
echo "Difference: $diff"
echo "Product: $prod"
#!/bin/bash
read -p "Enter a number to check: " a
if [ $(($a % 2)) -eq 0 ]
then
echo "Number is Even."
else
echo "Number is Odd."
fi
#!/bin/bash
read -p "Enter a number to check: " a
if [ $a -ge 0 ]; then
echo "Number is positive."
else
echo "Number is negative."
fi
#!/bin/bash
a=$1
b=$2
c=$3
largest=$a
smallest=$a
if [ $a -gt $b ] && [ $a -gt $c ]
then
largest=$a
elif [ $b -gt $a ] && [ $b -gt $c ]
then
largest=$b
else
largest=$c
fi
echo "Largest: $largest"
if [ $a -lt $b ] && [ $a -lt $c ]
then
smallest=$a
elif [ $b -lt $a ] && [ $b -lt $c ]
then
smallest=$b
else
smallest=$c
fi
echo "Smallest: $smallest"