Bash program to check if the Number is a Palindrome?


To check whether a number is palindrome or not, we have to reverse the number, and then if the actual number and the reversed number are same, then this is palindrome. In Bash, performing the reverse operation is very easy. We have to use the ‘rev’ command to do that. Let us see the program to understand clearly.

Example

#!/bin/bash
# GNU bash Script
n=12321
rev=$(echo $n | rev)
if [ $n -eq $rev ]; then
   echo "Number is palindrome"
else
   echo "Number is not palindrome"
fi

outline

Number is palindrome

Updated on: 30-Jul-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements