1

I would like to return an array from a function in ksh93.

At this point, using the following method, the contents of the array are passed as a single element even though, in the fonction, the array is seen as containing 48 elements.

The fonction is called like so :

function_name Variable_Name  

In the function I declare a local variable an assign to it the variable name local to the calling script.

typeset __NOM=$1  

Later in the function I try to return the array this way:

eval ${__NOM}="'${ARRAY[@]}'"  

What I get as a result, is the content of the array but seen as containing 1 element and not the 48 seen in the function. All the data is present but as one big element.

I use this method with variables containing many elements and it works well.

Is it possible that it cannot work with arrays?

If not I will use a global variable. It will be simpler but it would have been nice to have it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.