Home >Backend Development >C++ >Bash program to check if a number is a palindrome?

Bash program to check if a number is a palindrome?

WBOY
WBOYforward
2023-08-28 20:45:06685browse

Bash program to check if a number is a palindrome?

To check if a number is a palindrome, we need to reverse the number, then if the original number and the reversed number are the same, it is a palindrome. In Bash, performing the reverse operation is very simple. We need to use the ‘rev’ command to achieve this. Let’s take a look at the program to understand more 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

The above is the detailed content of Bash program to check if a number is a palindrome?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete