write a shell program to check wheather a given string is
pallindrome or not?
Answers were Sorted based on User's Feedback
Answer / mahesh gupta
this script is written for bash :
echo Enter the string
read s
echo $s > temp
rvs="$(rev temp)"
if [ $s = $rvs ]
then
echo "it is palindrome"
else
echo " it is not"
fi
Is This Answer Correct ? | 21 Yes | 6 No |
Answer / ishita sen
echo Enter the string
read s
echo $s > temp
rvs="$(rcs temp)"
if [ $s = $rcs ]
then
echo "it is palindrome"
else
echo " it is not"
fi
Is This Answer Correct ? | 11 Yes | 5 No |
Answer / goutamkumar
len=0
i=1
tag=0
echo -n "Enter a String: "
read str
len=`echo $str | wc -c`
len=`expr $len - 1`
halfLen=`expr $len / 2`
while [ $i -le $halfLen ]
do
c1=`echo $str|cut -c$i`
c2=`echo $str|cut -c$len`
if [ $c1 != $c2 ] ; then
i=$halfLen
tag=1
fi
i=`expr $i + 1`
len=`expr $len - 1`
done
if [ $tag -eq 0 ]
then
echo "String is Palindrome"
else
echo "String is not Palindrome"
fi
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / sudhir
#!/bin/ksh
i=1
tag=0
print -n "Enter a String:"
read str
len=`echo $str | wc -c`
if [[ $len -eq 1 ]]
then
print "Enter a valid string"
exit 2;
fi
let len=len-1
let halflen=len/2;
while [[ $i -le $halflen ]]
do
c1=`echo $str | cut -c $i`
c2=`echo $str | cut -c $len`
if [[ $c1 != $c2 ]]
then
tag=1;
fi
i=`expr $i + 1`
len=`expr $len - 1`
done
if [ $tag -eq 0 ]
then
echo "String is Palindrome"
else
echo "String is not Palindrome"
fi
Is This Answer Correct ? | 0 Yes | 0 No |
Hi, I want to practise Unix korn shell scripting which i learnt 2 yr bfr. plz suggest software i can use to practise.
Print the 10th line without using tail and head command.
How does shell scripting work?
Hi All, Is it possible to create one file name only space or space in file name in UNIX and we can able to run that on Unix?
Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.
How to write an Auto scripting for deleting old files using shell script and made a cron job to run on daily basis
What is eval in shell script?
How to rename all the files in a folder having specific extension? Example: I have some files with extension (.txt) in a folder name 'Test'. I have to rename all the .txt files in a test and its subdirectories to .my extension.
What are the zombie processes?
Determine the output of the following command: name=shubham && echo ‘my name is $name’.
what is the meaning of First line of shell script ,what is meaning of #! pleas explain brifly
What happens when you type ls?