Shell
Shell
1 .To calculate the area and circumference of the circle given the radius
i="y"
case $ch in
1) result=$((n1 + n2))
echo "Sum = $result";;
2) result=$((n1 - n2))
echo "Subtraction = $result";;
3) result=$((n1 * n2))
echo "Multiplication = $result";;
4) result=$(echo "scale=2; $n1 / $n2" | bc)
echo "Division = $result";;
*) echo "Invalid choice";;
esac
largest=$a
5.Reverse of a number
clear
echo "Enter a number:"
read n
rev=0
x=0
y=1
sum=0
old=$n
8.factorial of a number
ans=1
for ((i = 1; i <= fact; i++)); do
ans=$((ans * i))
done
9.prime numbers
echo
10.palindrom string
clear
echo "Enter the string:"
read string
11.words,lines in file
clear
echo "Enter the filename:"
read file
if [ ! -f "$file" ]; then
echo "File not found!"
exit 1
fi
clear
echo "Enter the name of the employee:"
read name
if [ $n -eq 0 ]; then
echo "No numbers provided!"
exit 1
fi
for i in "$@"; do
sum=$((sum + i))
done
clear
hour=$(date +"%H")
clear
echo "Enter the string:"
read word