Solved

Bourne shell

Posted on 1998-12-18
4
1,346 Views
Last Modified: 2013-12-26
1)writte a shell script to find the lenght of a given string?
2)write a shell script to reverse a string?
3)writte a shell script to check the if a given string is a palindrome or not?
0
Comment
Question by:sumbat31
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1294944
length=`echo -n $string | wc -c`
reverse=`perl -e "print scalar reverse shift" "$string"`
if [ "$string" = "$reverse" ] ; then echo palindrome; fi
0
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1294945
Boy, ozo makes it look pretty simple!
0
 

Accepted Solution

by:
aditya070797 earned 20 total points
ID: 1294946
Try this instead of using embedded perl (which probably defeats the purpose of the exercise):

#!/bin/sh
length=`echo  $string | wc -c` # Thanks OZO
reverse=`echo $string | rev` # Note that the rev command is available on HP-UX 11.0
if [ $string = $reverse ]
then
     echo $string is a palindrome
else
      echo $string is not a palindrome
fi
Thanks,
--Aditya.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6823643
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.

This is the Community Support link, if help is needed, along with the link to All Topics since many new ones were recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question