Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Jun 2006 20:43:45 +0530
From:      "Joseph Koshy" <joseph.koshy@gmail.com>
To:        "Michael Schuh" <michael.schuh@gmail.com>
Cc:        freebsd-hackers@freebsd.org, freebsd-stable@freebsd.org
Subject:   Re: Scope of Variables in sh
Message-ID:  <84dead720606010813u5c5a3f6fo75c19b7f02e87f18@mail.gmail.com>
In-Reply-To: <1dbad3150606010728l379e4c23p1a77558800498806@mail.gmail.com>
References:  <1dbad3150606010728l379e4c23p1a77558800498806@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> but this doesnt function right. so i see the behavior from
> $myline in the while-loop like an local variable......

If you are looking for function local variables,
use the "local" keyword.  For example:

++++ a.sh ++++
a=1
f()
{
        local a
        a=2
        echo B: In f: $a
}
echo A: Outside f: $a
f
echo C: Outside f: $a
++++++++

% sh a.sh
A: Outside f: 1
B: In f: 2
C: Outside f: 1

-- 
FreeBSD Volunteer,     http://people.freebsd.org/~jkoshy



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?84dead720606010813u5c5a3f6fo75c19b7f02e87f18>