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