Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
variables set on command line
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sam Steingold  
View profile  
 More options Aug 24 2011, 11:24 am
Newsgroups: gnu.bash.bug
From: Sam Steingold <s...@gnu.org>
Date: Wed, 24 Aug 2011 11:24:38 -0400
Local: Wed, Aug 24 2011 11:24 am
Subject: variables set on command line
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).

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

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=
exit

i.e., variables set in "a=a b=b f" survive to the next command.
$ /bin/sh --version
GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)

is this the expected behavior?

thanks.

--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031
http://palestinefacts.org http://openvotingconsortium.org http://memri.org
http://www.PetitionOnline.com/tap12009/ http://dhimmi.com
He who laughs last thinks slowest.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Blake  
View profile  
 More options Aug 24 2011, 11:31 am
Newsgroups: gnu.bash.bug
From: Eric Blake <ebl...@redhat.com>
Date: Wed, 24 Aug 2011 09:31:45 -0600
Local: Wed, Aug 24 2011 11:31 am
Subject: Re: variables set on command line
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   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Steingold  
View profile  
 More options Aug 24 2011, 12:07 pm
Newsgroups: gnu.bash.bug
From: Sam Steingold <s...@gnu.org>
Date: Wed, 24 Aug 2011 12:07:14 -0400
Local: Wed, Aug 24 2011 12:07 pm
Subject: Re: variables set on command line

> * Eric Blake <roy...@erqung.pbz> [2011-08-24 09:31:45 -0600]:
>> 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

This sucks big time.
So if I want to bind a variable for an eval invocation and do this:

  eval "`./libtool --tag=CC --config | grep '^archive_cmds='`"
  CC='${CC}' libobjs='$libs' deplibs='${CLFLAGS}' compiler_flags='${CFLAGS}' \
    soname='$dll' lib='$lib' output_objdir='$dyndir' \
    eval XCC_CREATESHARED=\"${archive_cmds}\"

and I want CC to have an old value after the second eval, I need to save
it and restore it by hand, like this:

  CC_save=$CC
  CC='${CC}' libobjs='$libs' deplibs='${CLFLAGS}' compiler_flags='${CFLAGS}' \
    soname='$dll' lib='$lib' output_objdir='$dyndir' \
    eval XCC_CREATESHARED=\"${archive_cmds}\"
  CC=$CC_save

however, this does not distinguish between unset CC and CC=''.
(is there a way to distinguish these two situations?)

thanks!

--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031
http://ffii.org http://palestinefacts.org http://honestreporting.com
http://thereligionofpeace.com http://openvotingconsortium.org http://dhimmi.com
Abandon all hope, all ye who press Enter.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Blake  
View profile  
 More options Aug 24 2011, 12:19 pm
Newsgroups: gnu.bash.bug
From: Eric Blake <ebl...@redhat.com>
Date: Wed, 24 Aug 2011 10:19:06 -0600
Local: Wed, Aug 24 2011 12:19 pm
Subject: Re: variables set on command line
On 08/24/2011 10:07 AM, Sam Steingold wrote:

>> * Eric Blake<roy...@erqung.pbz>  [2011-08-24 09:31:45 -0600]:
>>> 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

> This sucks big time.

Such is life when dealing with shell portability.

Yes - autoconf does this all the time, using an idiom roughly like this:

CC_set=${CC+set}
CC_save=$CC
do stuff that modifies $CC
if test "$CC_set" = set; then
   CC=$CC_save
else
   unset CC
fi

Also, you can use command to suppress the ability of built-ins like eval
(but not function calls) to affect the current environment:

$ unset foo
$ foo=bar eval :
$ echo $foo
bar
$ unset foo
$ foo=bar command eval :
$ echo $foo
$

--
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »