1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./export.sh <function name>
|
5 |
|
6 | #set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | printenv() {
|
11 | spec/bin/printenv.py "$@"
|
12 | }
|
13 |
|
14 | f1() {
|
15 | local f1_str=f1_str
|
16 | local f1_exported=f1_exported
|
17 |
|
18 | export f1_exported
|
19 |
|
20 | echo -n 'in f1: '
|
21 | printenv f1_exported
|
22 |
|
23 | f1_global=f1_global
|
24 | export f1_global
|
25 |
|
26 | # f1_exported gets CLEANED UP here.
|
27 | }
|
28 |
|
29 | f1
|
30 |
|
31 | echo $f1_str
|
32 | # This doesn't look in the environment? Oh I guess it gets cleaned up at the
|
33 | # end.
|
34 |
|
35 | echo -n 'global: '
|
36 | printenv f1_exported
|
37 | echo $f1_exported
|
38 |
|
39 | f1_global=AAA # mutate exported variable
|
40 | echo $f1_global
|
41 | printenv f1_global
|
42 |
|
43 | # oil:setandexport
|
44 | export E1=E1_VAL
|
45 | printenv E1
|
46 | unset E1
|
47 | echo "E1: $E1" # no longer set
|
48 | printenv E1 # no longer exported
|
49 |
|
50 | export E1=E1_VAL
|
51 | export -n E1
|
52 | echo "E1: $E1" # Still set! export and export -n aren't inverses.
|
53 | printenv E1
|
54 |
|
55 | echo ---
|
56 |
|
57 | myexport() {
|
58 | # hm this is fully dynamic. Not statically parseable!
|
59 | export "$@"
|
60 | }
|
61 | E3=E3_VAL
|
62 | myexport E2=E2_VAL E3
|
63 | echo "E2: $E2"
|
64 | echo "E3: $E3"
|
65 | printenv E2 E3
|