|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
What scripting language?
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
bash shell script
|
|
#4
|
|||
|
|||
|
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
$ |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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? |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
That's correct.
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
then I have another issue. how to assign an array value to another one i.e. clone?
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 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 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 |
|
|