Home > Backend Development > C++ > body text

Bash program to check if a number is a palindrome?

WBOY
Release: 2023-08-28 20:45:06
forward
677 people have browsed it

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
Copy after login

Outline

Number is palindrome
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template