Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bourne shell

Posted on 1998-12-18
4
Medium Priority
?
1,355 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 85

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 80 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 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