]>
Commit | Line | Data |
---|---|---|
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 | ||
17 | unset bar | |
18 | declare -n foo="bar" | |
19 | declare -p foo | |
20 | ||
21 | declare +n foo | |
22 | declare -p foo bar | |
23 | ||
24 | declare -n foo | |
25 | declare -p foo | |
26 | ||
27 | # let's try removing the nameref attribute -- other attributes and assignments | |
28 | # apply to the nameref target | |
29 | ||
30 | declare +n -i foo=7+4 | |
31 | declare -p foo bar | |
32 | ||
33 | unset 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 | ||
38 | declare -n foo6 | |
39 | declare -xi foo6 | |
40 | declare -p foo6 | |
41 | ||
42 | # and when we remove the nameref attribute, the other attributes remain | |
43 | ||
44 | declare +n foo6 | |
45 | declare -p foo6 | |
46 | ||
47 | unset foo6 | |
48 | ||
49 | # make sure these cases continue to work | |
50 | ||
51 | # nameref referencing an existing, set variable | |
52 | declare -n foo=bar | |
53 | bar='Hello World!' | |
54 | declare -p foo bar | |
55 | declare +n foo | |
56 | declare -p foo bar | |
57 | unset foo bar | |
58 | ||
59 | # nameref referencing an existing, unset variable | |
60 | declare -n foo=bar | |
61 | declare bar | |
62 | declare -p foo bar | |
63 | declare +n foo | |
64 | declare -p foo bar |