Saturday 2 November 2013

String Palindrome

#shell script to check whether inputted string is palindrome

#!/bin/bash

echo "Enter string"
read myn
i=1
leng=`expr length $myn`
flag=true
while [ $i -le $leng ]
do
myf=`echo $myn | cut -c $i`
mylf=`echo $myn | cut -c $leng`

    if [ $myf != $mylf ]; then

flag=false
    fi
i=`expr $i + 1`
leng=`expr $leng - 1`
done

if [ $flag == true ]; then
echo "String is palindrome"
else
echo "String is not palindrome"

fi

No comments:

Post a Comment