Unix/Linux Go Back    



function return array

Shell Programming and Scripting




Kindly Note - This is a Single User Post by Forum Member Annihilannic Regarding:
function return array.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 05-05-2008   -   Original Discussion by dophine
Annihilannic Annihilannic is offline Forum Advisor  
 
Join Date: May 2008
Last Activity: 28 October 2009, 7:03 PM EDT
Location: Sydney, Australia
Posts: 1,009
Thanks: 0
Thanked 2 Times in 2 Posts
A function can only return a return code, which is a cardinal (positive integer or zero).

However a function can modify an array held in the calling script.


Code:
$ cat function_return_array
#!/bin/bash

function myarray()
{
        a[1]=moja
        a[3]=three
}

a[1]=one
a[2]=two

myarray

echo ${a[1]}
echo ${a[2]}
echo ${a[3]}
$ ./function_return_array
moja
two
three
$