- #!/bin/bash
- # Read the number from user input
- echo "Enter a number: "
- read num
- # Initialize an empty variable to store the reversed number
- rev=0
- # Store the original number
- on=$num
- # Reverse the number
- while [ $num -gt 0 ]
- do
- # Get the last digit
- k=$(($num % 10))
- # Reverse the number by adding the last digit to the right
- # of the reversed number
- rev=$(($rev * 10 + $k))
- # Remove the last digit from the number
- num=$(($num / 10))
- done
- # Check if the original number and the reversed number are the same
- if [ $on -eq $rev ]
- then
- echo "The number is a palindrome."
- else
- echo "The number is not a palindrome."
- fi