create array holding characters from sring then echo array.

Hi,

I wish to store $string1 in $string1array[] a character in each array element.
Then i wish to echo the entire array to the screen so that it reads as the normal string again.

I have been trying with the code below but does not work. Please help...

To put string into array:

#!/bin/bash
length=$ ## Int length of string1
 noletter=1
 cnt=1
 x=0
while [ $noletter -le $length ]
do
  set -- $( echo $string1 | cut -c${cnt} )
  string1array[$x]=$1
  noletter=$(( noletter + 1 ))
  cnt=$(( cnt + 1 ))
  x=$(( $x + 1 ))
done

to echo array:

y=0
length = ##integer length of word
echo "Array is: "
while [ $y -lt $length ]
do
  echo -ne "${string1array[$y]} "
  y=$(( y + 1 ))
done

With zsh:

{ string=abcd
        for i ({1..$#string}) print -n $string
print;}

with recent bash versions:

{ string=abcd
i=0
while ((i<${#string}));do
	printf "%s " "${string:i:1}"
	((++i))
done
printf "\n";} 

Is this printing the array called string ?

It's printing the characters one by one ...

I am needing to have the characters stored in an array, so that I can compare them easily with a single character.

That can be done with code above too ...