Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

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-05-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

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:57 PM
Pass array to a function and display the array Girish19 Shell Programming and Scripting 7 02-18-2015 11:26 AM
Return a value from called function to the calling function mvictorvijayan Shell Programming and Scripting 1 09-14-2009 04:19 AM
return in function PRKS Shell Programming and Scripting 5 07-30-2009 08:15 AM
return value of a function fl0r10 Shell Programming and Scripting 5 07-06-2009 02:37 PM
Function's return value used inside awk Orbix Shell Programming and Scripting 4 12-09-2008 03:31 PM
need to return value from function darshakraut Shell Programming and Scripting 5 05-14-2008 08:13 AM
Return an array of strings from user defined function in awk user_prady Shell Programming and Scripting 2 12-03-2007 11:03 PM
Function to return an array of integer dwgi32 Programming 2 11-20-2007 01:08 AM
return value of a function prez Shell Programming and Scripting 3 08-22-2007 05:08 PM

All times are GMT -4. The time now is 06:53 AM.

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