ravi_rn
December 30, 2008, 4:12am
1
Hi,
I am using the following command to initialize and array
# arr[i]=ffffff00
# echo $arr
ffffff00
my requirement is i want to fetch the one by one character from array.
I don't know how to fetch one by one charcter from array.
Please i need an help.
Thank you very much
Ravi R N
pludi
December 30, 2008, 4:26am
2
echo ${arr}|perl -ne 'print join("\n",split(//,$_));'
and feed it into a read (or similar)
ravi_rn:
I am using the following command to initialize and array
# arr[i]=ffffff00
# echo $arr
ffffff00
my requirement is i want to fetch the one by one character from array.
I don't know how to fetch one by one charcter from array.
You have only initialized one element of the array. You might as well just use a scalar variable:
var=ffffff00
To get one character at a time from the variable:
var=ffffff00
while [ -n "$var" ]
do
temp=${var#?}
letter=${var%"$temp"}
printf "%s\n" "$letter"
var=$temp
done