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#
14declare -n r
15declare -n r
16unset -n r
17
18r=foo
19declare -n r=/
20
21r=%
22declare -n r
23unset r
24
25declare -n r
26r=^
27declare -p r
28
29unset -n r
30
31declare -n foo
32declare -a foo
33declare -p foo
34foo[0]=7
35declare -p foo
36unset foo
37
38declare -n x
39declare x=42
40declare -p x
41
42declare -n -r RO=foo
43declare -p RO
44
45unset -n r; unset r
46
47# the details of this may change; currently we put namerefs and values into
48# the tempenv if the nameref value is an invalid variable name
49f() { echo $r; }
50
51declare -n r
52r=/ ${THIS_SH} < /dev/null
53r=/ f
54
55unset -f f
56
57# the details of this may change; this will tell me when they do
58declare -n foo ; declare -i foo=7*6 ; declare -p foo
59unset -n foo
60declare -n foo ; declare -i foo ; foo=7*6 ; declare -p foo
61
62# used to be buggy
63f()
64{
65	unset var
66	declare -n ref=var
67	declare -n ref
68	declare -p ref
69}
70f
71
72unset -f f
73f()
74{
75	local var
76	declare -n ref=var
77	declare -n ref
78	declare -p ref
79}
80f
81
82unset ref; unset -n ref
83unset var
84
85var=foo
86typeset -n ref=var[0]
87readonly ref
88typeset -p var
89
90var2=foo
91typeset -n ref2=var2
92readonly ref2
93typeset -p var2
94
95unset var
96unset -n ref ref2
97
98unset var; typeset -n ref=var
99ref[0]=foo
100typeset -p ref var
101unset -n ref
102
103unset var; typeset -n ref
104ref[0]=foo
105typeset -p ref
106unset -n ref
107
108ref=global
109f() { declare -n ref=var; ref[0]=foo1; }; f
110f() { declare -n ref=var; ref[0]=foo2; }; f
111declare -p ref var
112
113declare -p global
114