LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2005, 09:26 AM   #1
kv_kumaravel
LQ Newbie
 
Registered: May 2005
Location: india
Posts: 2

Rep: Reputation: 0
Red face shell script


hi
i need a shell program for reversing a string and check is it palindrome or not.

bye
:tisk:
 
Old 05-16-2005, 09:37 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
For the first part, try :
Code:
echo "Hello, here" | rev
 
Old 05-16-2005, 10:27 AM   #3
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Rep: Reputation: 30
Code:
 #!/bin/bash

# specify palindrome possibility

if [ $# -eq 0 ] ; then
  echo Usage: $0 possible palindrome >&2
  exit 1
fi

testit="$(echo $@ | sed 's/[^[:alpha:]]//g' | tr '[:upper:]' '[:lower:]')"
backwards="$(echo $testit | rev)"

if [ "$testit" = "$backwards" ] ; then
  echo "$@ is a palindrome"
else
  echo "$@ is not a palindrome"
fi

exit 0
 
Old 05-17-2005, 06:21 PM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
why not just
Code:
$ test $(echo "$mystring") = $(echo "$mystring" | rev)
--Jonas
 
Old 05-18-2005, 12:45 PM   #5
mohit dhawan
Member
 
Registered: Mar 2005
Posts: 92

Rep: Reputation: 15
if u pass the arguments thrrough cmd line then
loop using for and store them in x
eg:- for y in $@
x= "$y" "$x"
and then chek it with ur $@
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration