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# exporting namerefs and putting namerefs in temp env post bash-4.3
15
16typeset -nx ref=var;
17typeset -p ref
18
19var=foo; str=''
20printenv ref                 # var
21ref+=$str    printenv ref    # var
22ref+="$str"  printenv ref    # var
23ref=$ref$str printenv ref    # var
24
25export ref		# follows nameref and exports var
26
27printenv var                 # foo
28ref+=$str    printenv var    # foo
29ref+="$str"  printenv var    # foo
30ref=$ref$str printenv var    # foo
31
32# none of these should change ref; should follow the nameref and export var
33unset var; unset -n ref; typeset -n ref=var
34
35echo before
36typeset -p ref var
37
38echo first
39ref=xxx typeset -p ref var
40
41echo invalid
42var= ref=5 typeset -p ref var
43
44echo after
45typeset -p ref var
46
47# ref isn't exported, so none of the printenvs should print anything
48unset var ; unset -n ref
49typeset -n ref=var;
50typeset -p ref
51
52var=foo; str=''
53printenv ref
54ref+=$str    printenv ref
55ref+="$str"  printenv ref
56ref=$ref$str printenv ref
57