]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
1 | # This program is free software: you can redistribute it and/or modify |
2 | # it under the terms of the GNU General Public License as published by | |
3 | # the Free Software Foundation, either version 3 of the License, or | |
4 | # (at your option) any later version. | |
5 | # | |
6 | # This program is distributed in the hope that it will be useful, | |
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 | # GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | # | |
a0c0a00f CR |
14 | # post-bash-4.3 changes for more ksh93 compatibility when following nameref |
15 | # chains and using typeset/declare -n to operate on nameref variables rather | |
16 | # than the variables they reference | |
17 | ||
18 | # don't follow nameref chain when using declare -n and at the global scope | |
19 | unset -n r1 r2 | |
20 | ||
21 | typeset -n r1=r2 | |
22 | typeset -n r2=x | |
23 | typeset -n r1=y | |
24 | ||
25 | typeset -p r1 r2 x y | |
26 | ||
27 | # same behavior when in a shell function | |
28 | foo() | |
29 | { | |
30 | typeset -n r1=r2 | |
31 | typeset -n r2=x | |
32 | typeset -n r1=y | |
33 | ||
34 | typeset -p r1 r2 x y | |
35 | } | |
36 | unset -n r1 r2 | |
37 | foo | |
38 | unset -f foo | |
39 | ||
40 | # same behavior when namerefs aren't chained | |
41 | unset -n r1 r2 | |
42 | ||
43 | typeset -n r1=z | |
44 | typeset -n r2=x | |
45 | typeset -n r1=y | |
46 | typeset -p r1 r2 x y | |
47 | ||
48 | # same behavior when referenced variables have values | |
49 | unset -n r1 r2 | |
50 | ||
51 | x=one | |
52 | y=two | |
53 | typeset -n r1=r2 | |
54 | typeset -n r2=x | |
55 | typeset -n r1=y | |
56 | ||
57 | typeset -p r1 r2 x y |