Home > Article > Backend Development > 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.
#!/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
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!