B.Sc Computer Science with Data analytics
Linux and Shell Programming - Lab
Bharathiar University
Program 9- Write a shell script to check whether given string is palindrome or not.
Source Code
# Main program starts here
# Prompt the user to enter the string
echo "Enter the string: "
read str
reversed=$(echo "$str" | rev)
if [ "$str" = "$reversed" ]; then
echo "The string '$str' is a palindrome."
else
echo "The string '$str' is not a palindrome."
fi
Sample OUTPUT:
No comments:
Post a Comment