pass by reference in shell

Hi,

I would like to write a function which takes one integer argument and adds 10 to it. But, I'd like to return the result in the data that was passed in. Is this possible?

function1()
{
1=$(($1+10))
}

my_number=1
function "$my_number"
echo $my_number

I'd like the echo statement to print 11 in this case. Is that the right syntax? I don't have a shell to test with right now... I appreciate your help. Thanks.

We need to know precisely which shell you are using. This is moving towards variable scoping, which varies from shell to shell, even from one version of the shell to another.

There are two types of functions in ksh, posix functions and the other kind. Since I can't find an official name for them, I dub them "useful functions".

Posix functions are of the form:
func1() { some-commands ; }
Use them if you like screwy side effects.

Useful functions are of the form:
function func1 { some-commands ; }

You are using the posix syntax.

With useful functions, you can declare variables inside the function with the typeset command. These are local variables. Other variables are global and are visable after the function exits. With posix functions, there are no local variables.

One option is to set global variables inside the function. But I think that stinks. So my solution would be:

function func1
{
echo $(($1 +10))
return 0
}

my_num=1
my_num=$(func1 $my_num)

This is closer to the fortran concept of functions than it is to c functions.