Headlines
Loading...
Program in UNIX to check entered string is palindrome or not

Program in UNIX to check entered string is palindrome or not

Write a shell script to check entered string is palindrome or not

echo -n "enter string: "
read str

flag=0
cnt=`expr $str : '.*'`

i=1
l=`expr $cnt / 2`

while [ $l -gt $i ]
do
  c1=`echo $str|cut -c$i`
  c2=`echo $str|cut -c$cnt`
  if [ $c1 !=  $c2 ]
  then
        flag=1
        break
  fi
  i=`expr $i + 1`
  cnt=`expr $cnt - 1`
done

if [ $flag -eq 1 ]
then
     echo "Not palindrome"
else
     echo "Palindrome"
fi
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***