#!/bin/bash
# Shell script to test if a string is a palindrome
# This simply uses the 'rev' command found in util-linux-ng package
# and checks if the reverse of the string is same as the original
echo "Enter a String : "
read string
if [ "$(echo $string | rev)" = "$string" ]
then
echo "\"$string\" IS a Palindrome"
else
echo "\"$string\" IS NOT a Palindrome"
fi

1 Kommentar:

There is another command "yes". That just outputs "y" in the standard output. This is the most useless. Most of the bash commands, when used alone are useless. Each of them are designed to do a very specific job. These gives you a toolbox. To achieve a task then you can use more than one commands in conjunction to do complex tasks. For the case of rev, let's say, you have a log file from which you filter out lines with some specific paths related to some kind of software crash or whatever. You need to find last component of the path (ex. /use/bin/bash , need to get "bash"). In this case you can first rev the line and then cut the first field and the rev again. cat log | grep pattern | rev | cut -d '/' -f 1 | rev . You can do this with awk, or any other stuffs, but the main idea of the useless commands or the commands of very little use is to provide basic functionality, which in combination can bring extreme flexibility and power.