]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/nameref15.sub
Bash-5.2 patch 32: fix printing coprocs when the coproc does not have a name
[thirdparty/bash.git] / tests / nameref15.sub
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 #
14 f() { local -n a=$1; a=X; }
15
16 a=(0); f 'a[0]'
17 while [[ -v a ]]; do declare -p a; unset a; done
18
19 a=(0); f 'a'
20 while [[ -v a ]]; do declare -p a; unset a; done
21
22 b=(0); f 'b[0]'
23 while [[ -v a ]]; do typeset -p a; unset a; done
24 typeset -p b
25
26 b=(0); f 'a[0]'
27 while [[ -v a ]]; do typeset -p a; unset a; done
28 typeset -p b
29
30 add_X_echo()
31 {
32 typeset -n ref=$1
33 ref+=X
34 echo inside $ref
35 }
36
37 ref=
38 add_X_echo ref
39 echo outside "$ref"
40 unset ref
41
42 # same test, but assigning nameref variable circular reference directly
43 xxx_func()
44 {
45 typeset -n xxx=xxx
46 xxx=foo
47 declare -p xxx
48 echo $FUNCNAME: inside: xxx = $xxx
49 }
50
51 xxx=7
52 echo before: $xxx
53 xxx_func
54 echo after: $xxx
55
56 unset xxx
57 unset -f xxx_func
58
59 typeset -n ref=ref
60
61 typeset -n ref=re ref+=f
62 typeset -p ref
63 ref=4
64 typeset -p ref re
65
66 export ref
67 printenv ref
68 printenv re
69
70 unset ref ; unset -n ref
71 unset foo; unset -n foo
72
73 typeset -n foo=var[@]
74 typeset -p foo
75 typeset -n ref=var ref+=[@]
76 typeset -p ref
77
78 ref=42
79
80 typeset -n bar
81 bar=var[@]
82 typeset -p bar
83 bar=7
84
85 unset a b
86 unset -n a b
87
88 typeset -n a=b b
89 b=a[1]
90 typeset -p a b
91 a=foo
92 typeset -p a b
93
94 unset a
95 typeset -n a=b
96 declare a=foo
97 typeset -p a b
98
99 unset n v
100 unset -n n v
101
102 v=(0 1)
103 typeset -n n=v
104 unset n[0]
105 typeset -p n v
106
107 unset -n n
108
109 v=(0 1)
110 typeset -n n=v
111 unset -n n
112 typeset -p n v
113
114 v=(0 1)
115 declare -n n=v[1]
116 unset n
117 declare -p n v
118
119 declare -n xref
120 declare -a xref[1]=one
121 declare -p xref
122
123 unset xref
124 declare -n xref
125 xref=array
126 declare -a xref[1]=one
127 declare -p xref