]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/nameref8.sub
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / nameref8.sub
CommitLineData
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#
ac50fbac
CR
14function f1
15{
16 typeset -n v=$1
17
18 v=inside
19}
20
21v=global
22f1 v
23echo $v
24
25unset v
26unset -f f1
27
28function foo
29{
30 typeset x=one
31
32 typeset -n y=$1
33 y=two
34 echo inside: $x
35}
36
37foo x
38echo outside: $x
39
40function foo2
41{
42 typeset -n x=$1
43
44 x=foo
45}
46
47foo2 x
48echo $x
49
50unset -f foo
51function foo { typeset -n v=$1; v=local; }
52
53v=global
54foo v
55echo $v
56
57unset v
58
59# invalid self reference at global scope
60typeset -n v=v
61
62# can we catch a circular self-reference?
63typeset -n v=w
64typeset -n w=x
65typeset -n x=v
66
67x=4
68echo x = $x
69
70unset -n v w x
a0c0a00f
CR
71
72# can we keep local variables invisible when we add nameref attribute?
73function f { typeset x; typeset -n x; x=y; }
74f