]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/nameref19.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / nameref19.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#
d233b485
CR
14# can we unset the nameref attribute on variables with values that reference
15# unset variables?
16
17unset bar
18declare -n foo="bar"
19declare -p foo
20
21declare +n foo
22declare -p foo bar
23
24declare -n foo
25declare -p foo
26
27# let's try removing the nameref attribute -- other attributes and assignments
28# apply to the nameref target
29
30declare +n -i foo=7+4
31declare -p foo bar
32
33unset foo bar
34
35# but if the nameref variable doesn't have a value, the attributes apply to
36# the nameref variable itself. thanks ksh93
37
38declare -n foo6
39declare -xi foo6
40declare -p foo6
41
42# and when we remove the nameref attribute, the other attributes remain
43
44declare +n foo6
45declare -p foo6
46
47unset foo6
48
49# make sure these cases continue to work
50
51# nameref referencing an existing, set variable
52declare -n foo=bar
53bar='Hello World!'
54declare -p foo bar
55declare +n foo
56declare -p foo bar
57unset foo bar
58
59# nameref referencing an existing, unset variable
60declare -n foo=bar
61declare bar
62declare -p foo bar
63declare +n foo
64declare -p foo bar