Solved

Bourne shell

Posted on 1998-12-18
4
1,347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

734 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