2A) Swapping Values of Two Variables (swap.
sh)
echo -n "Enter value for A : "
read a
echo -n "Enter value for B : "
read b
t=$a
a=$b
b=$t
echo "Values after Swapping"
echo "A Value is $a and B Value is $b"
Output:
$ sh [Link]
Enter value for A : 12
Enter value for B : 23
Values after Swapping
A Value is 23 and B Value is 12
B) Fahrenheit to Centigrade Conversion ([Link])
echo -n "Enter Fahrenheit : "
read f
c=`expr \( $f - 32 \) \* 5 / 9`
echo "Centigrade is : $c"
Output:
$ sh [Link]
Enter Fahrenheit : 213
Centigrade is : 100
C) Biggest of Three Numbers ([Link])
echo -n "Give value for A B and C : "
read a b c
if [ $a -gt $b -a $a -gt $c ]
then
echo "A is the Biggest number"
elif [ $b -gt $c ]
then
echo "B is the Biggest number"
else
echo "C is the Biggest number"
fi
Output:
$ sh [Link]
Give value for A B and C : 4 3 4
C is the Biggest number
D) Grade Determination ([Link])
echo -n "Enter the mark : "
read mark
if [ $mark -gt 90 ]
then
echo "S Grade"
elif [ $mark -gt 80 ]
then
echo "A Grade"
elif [ $mark -gt 70 ]
then
echo "B Grade"
elif [ $mark -gt 60 ]
then
echo "C Grade"
elif [ $mark -gt 55 ]
then
echo "D Grade"
elif [ $mark -ge 50 ]
then
echo "E Grade"
else
echo "U Grade"
fi
Output
$ sh [Link] Enter the mark : 65
CGrade
E) Vowel or Consonant ([Link])
echo -n "Key in a lower case character : "
read choice
case $choice in
a|e|i|o|u) echo "It's a Vowel" ;;
*) echo "It's a Consonant" ;;
esac
F) Simple Calculator ([Link])
echo -n "Enter the two numbers : "
read a b
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
echo -n "Enter the option : "
read option
case $option in
1) c=`expr $a + $b`
echo "$a + $b = $c" ;;
2) c=`expr $a - $b`
echo "$a - $b = $c" ;;
3) c=`expr $a \* $b`
echo "$a * $b = $c" ;;
4) c=`expr $a / $b`
echo "$a / $b = $c" ;;
*) echo "Invalid Option" ;;
esac
Output
$ sh [Link]
Enter the two numbers : 2 4
2. Addition
3. Subtraction
4. Multiplication
Divisionoption : 1 2 + 4 = 6
G) Multiplication Table ([Link])
clear
echo -n "Which multiplication table? : "
read n
for x in 1 2 3 4 5 6 7 8 9 10
do
p=`expr $x \* $n`
echo "$n X $x = $p"
sleep 1
done
Output
$ sh [Link]
Enter a number : 234 Reversed number is432
H) Number Reverse ([Link])
echo -n "Enter a number : "
read n
rd=0
while [ $n -gt 0 ]
do
rem=`expr $n % 10`
rd=`expr $rd \* 10 + $rem`
n=`expr $n / 10`
done
echo "Reversed number is $rd"
I) Prime Number ([Link])
echo -n "Enter the number : "
read n
i=2
m=`expr $n / 2`
until [ $i -gt $m ]
do
q=`expr $n % $i`
if [ $q -eq 0 ]
then
echo "Not a Prime number"
exit
fi
i=`expr $i + 1`
done
echo "Prime number"
Output
$ sh [Link]
Enter the number : 17 Prime number