Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi, i need help regarding the following -
1)how to write a shell script in UNIX which would check whether an input string is a palindrome or not.
2) do we have arrays in unix to store numbers and characters ?
thanks.

A palindrome could have mixed case, punctuation, and spaces, any of which would mess up a reverse-order test, such as:
Are poets a waste? Opera!
To check that, your script would have to downshift or upshift entire string and ignore spaces and punctuation. But your assignment is probably to check if a single lowercase word is a palindrome, such as "racecar".
I know how to reverse the string in one very simple command, but I believe that would defeat the purpose of the assignment, which is to do some array work. The whole word sitting in one array slot is no use, so I would start by getting each letter of the word into separate array slots. Any ideas on how you might break up that word?

The script below takes whatever is on the command line and pulls each character out individually. I haven't used arrays much in Unix, so I'll leave that part to you. I ran this using the bash shell.
text=$@
textLength=`echo $text | wc -c`
i=1
while [ $i -le $textLength ]
dox=`echo $text | cut -c$i`
echo $x
i=$(( $i + 1 ))done

1) write shell programs for the following(in unix)
a) to remove from an ordered array all numbers that occurs
more than once.
b) to check whether a string is a palindrome or not.
c) to sort the given list of numbers using bubble sort.Pl. send me the above list of programs immdtly anyone.

![]() |
Question for a Linux/Unix...
|
Compress/Uncompress in UN...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |