SHELL SCRIPT_
SHELL SCRIPT_
#!bin/bash
echo “enter the number:”
read radius
pi=3.14
area=$(echo “$pi*$radius*$radius”|bc)
circumference=$(echo “2*$pi*$radius”|bc)
echo “$area”
echo “$circumference”
OUTPUT:
SHELL SCRIPT:
#!bin/bash
echo “enter a:”
read a
echo “enter b:”
read b
echo “enter c:”
read c
n=$(echo “$b*$b-4*$a*$c”|bc -l)
r1=$(echo “(-$b+sqrt($n))/(2*$a)”|bc -l)
r2=$(echo “(-$b-sqrt($n))/(2*$a)”|bc -l)
echo “$r1”
echo “$r2”
OUTPUT:
SHELL SCRIPT:
#!bin/bash
echo “enter the word:”
read word
echo “$word” | tr -cd ‘aeiouAEIOU’ | wc -c
echo “vowels”
OUTPUT:
SHELL SCRIPT:
#!bin/bash
echo "Enter the year"
read y
b=`expr $y % 4`
if [ $b -eq 0 ]
then
echo "$y is a leap year"
else
echo "$y is not a leap year"
fi
OUTPUT:
SHELL SCRIPT:
#!/bin/bash
echo "enter three numbers:"
read num1
read num2
read num3
if [ $num1 -ge $num2 ] && [ $num1 -ge $num3 ]; then
max=$num1
elif [ $num2 -ge $num1 ] && [ $num2 -ge $num3 ]; then
max=$num2
else
max=$num3
fi
echo "the greatest number is: $max"
OUTPUT:
SHELL SCRIPT:
#!/bin/bash
echo "Enter marks for 5 subjects:"
read m1 m2 m3 m4 m5
sum=$((m1 + m2 + m3 + m4 + m5))
percentage=$((sum / 5))
echo "sum of 5 subjects is: $sum"
echo "the percentage is: $percentage"
if [ $percentage -ge 75 ]
then
echo "you got distinction"
elif [ $percentage -ge 60
then
echo "you got first class"
elif [ $percentage -ge 50 ]
then
echo "you got second class"
elif [ $percentage -ge 35 ]
then
echo "you passed"
else
echo "you failed"
fi
OUTPUT:
SHELL SCRIPT:
#!/bin/bash
echo "Type one of the following options:"
echo "1. who am i"
echo "2. who is logged on"
echo "3. date"
echo "4. calendar"
read choice
case $choice in
1) whoami ;;
2) who ;;
3) date ;;
4) cal ;;
*) echo "Invalid option" ;;
esac
OUTPUT: