bug-bash
[Top][All Lists]
Advanced

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

Re: output of `export -p' seems misleading


From: Greg Wooledge
Subject: Re: output of `export -p' seems misleading
Date: Fri, 9 Nov 2012 11:18:24 -0500
User-agent: Mutt/1.4.2.3i

On Fri, Nov 09, 2012 at 11:07:28AM -0500, Chet Ramey wrote:
> On 11/9/12 4:09 AM, wuya wrote:
> >    2. this format gives user an implication that by executing these 
> > `declare' commands, all those variables got exported, but this is only 
> > partly true as it fails in functions.
> 
> That's not quite true.  The documentation implies, though maybe not as
> clearly as possible, that each name argument to declare/export/readonly is
> treated as a variable name by default.  The -f option is what you need to
> refer to functions.

I believe wuya wants to be able to use the output of "export -p"
while INSIDE a function in order to restore some previously saved set
of environment variables, but the side effect of "declare" -> "local"
is getting in the way (i.e. (s)he wants the variables to survive after
returning from the function).

However, since you said that the behavior changes when in POSIX mode, wuya
can use that as a workaround:

restore_environment() {
  set -o posix
  eval "$saved_output_of_export_dash_p"
  set +o posix
}



reply via email to

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