Re: wrong behaviour when unsetting/setting some variables

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

 



On Mon, 2024-02-26 at 23:23 -0500, Lawrence Velázquez wrote:
> They are not exported.
> 
> 	% env -i /opt/local/bin/dash
> 	$ export MAIL=v
> 	$ unset -v MAIL
> 	$ export
> 	export MAIL
> 	export PWD='/private/tmp'
> 	$ env
> 	PWD=/private/tmp
> 
> Their local counterparts are not exported, either.
> 
> 	% env -i /opt/local/bin/dash
> 	$ f() { local FOO=v; export FOO; unset -v FOO; export; env;
> }
> 	$ f
> 	export FOO
> 	export PWD='/private/tmp'
> 	PWD=/private/tmp

Interesting.
I guess it simply doesn't export any vars for which no value is set
(i.e. not even the empty value)?!


Is that POSIXly correct?


Even draft 4.1 says only:
> The shell shall give the export attribute to the variables
> corresponding to the specified names, which shall cause them to be
> in the environment of subsequently executed commands.
at the description of export.

It doesn't say that variables with just the attribute should not be
exported.

OTOH, 8.1 Environment Variable Definition says:
> The array is pointed to by the external variable environ, which is
> defined as:
> extern char **environ;
> These strings have the form name=value;

So one might argue, that env vars must have some =value, and that this
couldn't be done for exported shell vars with no (not even the empty)
value.


It does seem to export a local exported var, if it has some value.


Cheers,
Chris.





[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux