function return array

array, function, shell scripts

Login to Reply

Thread Tools Search this Thread
# 1  
Old 05-05-2008
function return array

Hi all

I would like to know if there is a way to return an array for a function.
As I know function can return all the contents in an array, I want to return an array type.
# 2  
Old 05-05-2008
What scripting language?
# 3  
Old 05-05-2008
bash shell script
# 4  
Old 05-05-2008
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.

$ cat function_return_array

function myarray()



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

# 5  
Old 05-05-2008
so the array seems act as a globle variable,right?
if a function is called several times in the script, then I need to store it in another array before calling it again, right?
# 6  
Old 05-06-2008
That's correct.
# 7  
Old 05-06-2008
then I have another issue. how to assign an array value to another one i.e. clone?
Login to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Return: can only `return' from a function or sourced script svajhala Shell Programming and Scripting 1 04-05-2018 02:57 PM
Pass array to a function and display the array Girish19 Shell Programming and Scripting 7 02-18-2015 12:26 PM
Return two dimensional array in c++ saboture88 Programming 4 06-12-2012 09:36 AM
getting return value from oracle function bongo Shell Programming and Scripting 12 04-23-2010 11:34 AM
Return a value from called function to the calling function mvictorvijayan Shell Programming and Scripting 1 09-14-2009 05:19 AM
return in function PRKS Shell Programming and Scripting 5 07-30-2009 09:15 AM
return value of a function fl0r10 Shell Programming and Scripting 5 07-06-2009 03:37 PM
need to return value from function darshakraut Shell Programming and Scripting 5 05-14-2008 09:13 AM
Function call not return value into var katzs500 UNIX for Dummies Questions & Answers 1 04-18-2008 10:31 PM
How to return void function pointer umen Programming 1 03-22-2008 05:01 PM
Return an array of strings from user defined function in awk user_prady Shell Programming and Scripting 2 12-04-2007 12:03 AM
Function to return an array of integer dwgi32 Programming 2 11-20-2007 02:08 AM
return value of a function prez Shell Programming and Scripting 3 08-22-2007 06:08 PM
To return the elements of array Sudhakar333 Shell Programming and Scripting 5 08-06-2007 03:20 PM
All times are GMT -4. The time now is 05:28 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.