bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variables set on command line


From: Eric Blake
Subject: Re: variables set on command line
Date: Wed, 24 Aug 2011 09:31:45 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

On 08/24/2011 09:24 AM, Sam Steingold wrote:
CYGWIN_NT-5.2-WOW64 sds 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin
BASH_VERSION='4.1.10(4)-release'

at the bash prompt I observe this:
$ f(){ echo a=$a b=$b c=$c ; }
$ unset a b c
$ a=a b=b f
a=a b=b c=
$ f
a= b= c=
which I believe is correct (i.e., variables set in "a=a b=b f" are unset
after f terminates).

This is bash's default behavior, but it violates POSIX.


alas, when I call /bin/sh on the same machine, I see this:

That tells bash to strictly obey POSIX, so you get the POSIX behavior.


f(){ echo a=$a b=$b c=$c ; }
f
a= b= c=
a=a b=b f
a=a b=b c=
f
a=a b=b c=

Which is indeed correct under the rules for POSIX (basically, POSIX requires function calls to behave like special built-ins, such that changes to the environment persist after the function call - the bash developer thinks the posix rule is counterintuitive, which is why the default bash behavior is opposite the posix behavior).

Your question is not cygwin-specific.

is this the expected behavior?

Yes.

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]