I tried doing a "return <array name>" in the function and tried a
set -A arr `func1`
but it did not work.
The array elements have space delimited data. So it is important that
i use an array and not a string.
This script runs on a linux box.
Please let me know.
Thanks,
Reuben.
"return" only can only be used to return a single numeric value
Seems to me that the array should also be visible outside the
function unless you have declared it local to the function
(such as doing a "typeset -A arr")
an alternative to the return <arr> would be to print it to
stdout and capture the function output with command substitution
var=$(func1 <args>)
He pointed out the problem with that: the array elements can contain
spaces. When you do this, you lose the distinction between the spaces
separating the elements and the spaces within the elements.
If there's some character that can never appear within an element, you
can use that as the element separator when your function prints its
results. Then the caller can do:
IFS=<char>
set -A arr `func1`
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
right...as in this works (with or without the typeset)
#!/bin/bash
typeset -a arr
function myf {
arr[1]=a
arr[2]=b
echo ${arr[@]}
}
myf
echo ${arr[@]}
while this doesn't (as the array scoped inside the function)
#!/bin/bash
function myf {
typeset -a arr
arr[1]=a
arr[2]=b
echo ${arr[@]}
}
myf
echo ${arr[@]}
~
for a real treat.....
#!/bin/bash
typeset -a arr
arr[1]=Z
arr[2]=X
function myf {
typeset -a arr
arr[1]=a
arr[2]=b
echo ${arr[@]}
}
myf
echo ${arr[@]}
which illustrates the scoping