1 |
2010-07-31 22:25:26 Petteri Räty napisał(a): |
2 |
> On 07/31/2010 11:10 PM, Arfrever Frehtes Taifersar Arahesis wrote: |
3 |
> >> |
4 |
> >> If the variable is set but not exported then it is local to the shell |
5 |
> >> env. When bash goes to exec() python the local shell variables are |
6 |
> >> not in the env; so os.environ() will not contain them. |
7 |
> >> |
8 |
> >> antarus@kyoto ~ $ foo=BAR |
9 |
> >> antarus@kyoto ~ $ echo $foo |
10 |
> >> BAR |
11 |
> >> antarus@kyoto ~ $ python -c 'import os; print os.environ.get("foo")' |
12 |
> >> None |
13 |
> >> antarus@kyoto ~ $ export foo |
14 |
> >> antarus@kyoto ~ $ python -c 'import os; print os.environ.get("foo")' |
15 |
> >> BAR |
16 |
> > |
17 |
> > I want only variables exported to Python processes. |
18 |
> > |
19 |
> |
20 |
> export -p |
21 |
|
22 |
It would have to be parsed using e.g. grep and sed. It's easier to call Python in this case. |
23 |
The call to Python is sufficiently fast: |
24 |
|
25 |
$ time python -c 'import os; print(os.environ.get("LC_ALL", os.environ.get("LC_CTYPE", os.environ.get("LANG", "POSIX"))))' > /dev/null |
26 |
|
27 |
real 0m0.062s |
28 |
user 0m0.051s |
29 |
sys 0m0.011s |
30 |
|
31 |
-- |
32 |
Arfrever Frehtes Taifersar Arahesis |