[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NOT changing global variables
From: |
Frans de Boer |
Subject: |
Re: NOT changing global variables |
Date: |
Fri, 29 Dec 2006 23:43:14 +0100 |
Yes, I did expected such an answer of using a subshell, and yes I can
get the return value, but I don need it. I need the output fed into
another (maybe local) variable. I was under the impression that BASH was
modeled after 'C', so I started using the functions as such. My mistake.
I have the confirmation that it's not so strait forward as I expected.
Never mind, I now know better, so thanks for the comment anyway.
KR,
Frans de Boer (NL).
On Fri, 2006-12-29 at 18:56 +0100, Andreas Schwab wrote:
> Frans de Boer <frans@fransdb.nl> writes:
>
> > Okay, the function tries to alter the global var1 integer. But, the
> > result is that var1 is NOT changed.
>
> Yes, because the function is executed in a subshell.
>
> > So, the result of the first echo
> > will be 0
> > However, the next echo displays the changed var1 as being 1. At the
> > expense of losing the return value.
>
> You are not using the return value of the function but its output. The
> return value of a function is the exit status of the last executed
> command, and can also be set with return. The return value is available
> in $?.
>
> Andreas.
>