Solved

Bourne shell

Posted on 1998-12-18
4
1,340 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

14 Experts available now in Live!

Get 1:1 Help Now