Bourne shell

Posted on 1998-12-18
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?
Question by:sumbat31
LVL 84

Expert Comment

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

Expert Comment

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

Accepted Solution

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

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 ]
     echo $string is a palindrome
      echo $string is not a palindrome

Expert Comment

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.
Moderator @ Experts Exchange

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 120
repeateFront java challenge 31 92
Host to IP 7 76
ORA-01403: no data found 43 89
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now