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
What is difference between shell and bash scripting?
What does $$ mean in shell script?
How do I run a shell script in powershell?
how to get part of string variable with echo command only?
How to check if a directory exists?
What is the purpose of scripting?
Write a shell script to get current date, time, user name and current working directory.
What is awk in shell script?
What is the use of "$#" in shell scripting?
one folder contains lot of students name but I want to fetch hello with every student name individually using shell script
Explain about the slow execution speed of shells?
What is the difference between break and continue commands?
What is another name for a bash shell script that you might see?
What is bourne shell scripting?
What is the lifespan of a variable inside a shell script?