[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: output of `export -p' seems misleading
From: |
Chet Ramey |
Subject: |
Re: output of `export -p' seems misleading |
Date: |
Fri, 09 Nov 2012 11:07:28 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 |
On 11/9/12 4:09 AM, wuya wrote:
> Hi all,
> 1. why `export -p' output something in the format `declare -x foo="bar"'
Because the declare form is bash's `native' notation. If you're in Posix
mode, the output is in the form of `export' commands.
> 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.
> 3. As in bash 4.2, -g option is added. why not change output format of
> `export -p' to `declare -g foo="bar"'?
Because they are not at all the same thing. -x refers to the environment.
-g changes bash's internal variable scoping.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/