Shell Programs 1
Shell Programs 1
UTPUT
O
enter the number
12
12 is even number
UTPUT
O
enter the 3 numbers
10
5
40
40 is the greatest
ROGRAM
P
echo "Enter the no to check: "
read n
fact=1
if [ $n -eq 0 ]
then
echo "factorial is 1"
else
while [ $n -gt 0 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
echo "$fact is factorial"
fi
UTPUT
O
Enter the no to check:
5
120 is factorial
ROGRAM
P
echo "Enter the no of terms: "
read n
a=0
b=1
count=0
echo "Fibonacci series: "
while [ $count -lt $n ]
do
echo "$a "
a=`expr $a + $b`
b=`expr $a - $b`
count=` expr $count + 1 `
done
UTPUT
O
Enter the no of terms:
5
Fibonacci series:
0
1
1
2
3
ROGRAM
P
echo "Enter first number: "
read num1
echo "Enter second number: "
read num2
echo "Enter operation (+, -, *, /): "
read operation
if [ "$operation" == "+" ];
then result=$((num1 + num2))
elif [ "$operation" == "-" ];
then
result=$((num1 - num2))
elif [ "$operation" == "*" ];
then
result=$((num1 * num2))
elif [ "$operation" == "/" ];
then
if [ "$num2" -eq 0 ];
then
echo "Error: Division by zero!"
exit 1
else
result=$((num1 / num2))
fi
else
echo "Invalid operation!"
exit 1
fi
echo "Result: $result"
UTPUT
O
Enter first number:
10
Enter second number:
20
nter operation (+, -, *, /):
E
+
Result: 30