Shell Scripting Program to check if a Number is Palindrome

Palindrome Numbers are the numbers whose reverse will also give you the same number. For Example, 567 is not a palindrome number because the reverse of 567 is 765 which is not same as the number, whereas 8778 is a palindrome which on reverse will also give the same number.

Following is a shell scripting program to check if a number is Palindrome or not.

Explanation:

#!/bin/bash – This line tells the shell environment that this program is a bash script and /bin/ is the location in operating system where the bash is.

clear – will clear the bash terminal so that no other program will appear on that.

Later everything can be found on my earlier post. Here is the link if you haven’t seen it. http://www.anonhack.in/2018/04/bash-program-to-check-if-a-number-is-armstrongshell-scripting/ .

Code:
#!/bin/bash
clear
echo "Enter No : "
read no

m=$no
rev=0

while [ $no -gt 0 ]
do
            r=`expr $no % 10`
            rev=`expr $rev \* 10 + $r`
            no=`expr $no / 10`
done

if [ $m = $rev ]
then
            echo " $m is Palindrome"
else
            echo " $m is not Palindrome"
fi

OUTPUT:

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: