write a shell script to identify the given string is
palindrome or not?

Answer Posted / gaurav shah.ait

tput clear

echo -e "Enter String :- \c"
read str
len=`expr $str|wc -m `
len=`expr $len - 1`
len1=`expr $len `
echo -e "Reverse String :- \c"
while [ $len -ne 0 ]
do
s1=` expr $str|cut -c$len `
echo -e "$s1\c "
len=` expr $len - 1 `
done
len=`expr $str|wc -m `
len=`expr $len - 1`
echo ""
n=1
flag=0
while [ $len -ne 0 ]
do
fst=` expr $str|cut -c$n `
lst=` expr $str|cut -c$len `
len=` expr $len - 1 `
n=` expr $n + 1`

if test $fst != $lst
then
flag=1
fi
done
if test $flag = 1
then
echo "Given String Is Not Palindrome"
else
echo "Given String Is Palindrome"
fi

Is This Answer Correct ?    16 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I run a .sh file on mac?

779


What is the conditional statement in shell scripting?

742


How do we delete all blank lines in a file?

668


How do I open a jshell in cmd?

714


What is the fastest scripting language?

632






Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.

666


How do I read a .sh file?

606


Can we run shell script in windows?

663


Which shell is the best?

650


What is the significance of $#?

676


Explain about login shell?

708


How are shells born?

633


What is the significance of the shebang line in shell scripting?

636


What is the command to find out users on the system?

648


What is gui scripting?

699