Shell script to check number is Palindrome

Shell script to check number is Palindrome

Unix Shell script to check number is Palindrome

For Number :

echo “Enter a number to find for palindrome”
read num1
num=$num1
i=0

while [ $num -gt 0 ]
do
let i=i*10+num%10 # Using let for arithmetic operations
let num=num/10
done

if [ $i -eq $num1 ] ; then
echo “$num1 is a palindrome”
else
echo “$num1 is not a palindrome”
fi

For String :

echo “enter a string”
read str

var1=echo "$str" | rev
if [ “$var1” != “$str” ] ; then
echo “no pali”
else
echo “pali”
fi