Sunday, 17 June 2012

Write a shell script to check if the input string is a palindrome


if [ $# -gt 0 ]
then
x=`echo $1 | wc -c`
x=`expr $x - 1`
final=""
while [ $x -gt 0 ]
do
c=`echo $1 | cut -c $x`
x=`expr $x - 1`
final=$final$c
done
fi
if [ $final = $1 ]
then
echo String is palindrome
else
echo The string is not palindrome
fi

No comments:

Post a Comment