]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/nameref16.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / nameref16.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#
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
19unset -n r1 r2
20
21typeset -n r1=r2
22typeset -n r2=x
23typeset -n r1=y
24
25typeset -p r1 r2 x y
26
27# same behavior when in a shell function
28foo()
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}
36unset -n r1 r2
37foo
38unset -f foo
39
40# same behavior when namerefs aren't chained
41unset -n r1 r2
42
43typeset -n r1=z
44typeset -n r2=x
45typeset -n r1=y
46typeset -p r1 r2 x y
47
48# same behavior when referenced variables have values
49unset -n r1 r2
50
51x=one
52y=two
53typeset -n r1=r2
54typeset -n r2=x
55typeset -n r1=y
56
57typeset -p r1 r2 x y