]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/nameref10.sub
Bash-4.4 distribution sources and documentation
[thirdparty/bash.git] / tests / nameref10.sub
1 # testing behavior of command substitution as one of expansions performed by
2 # array subscripting; should behave the same directly as when done through
3 # a nameref
4
5 x[0]=42
6 zero=0
7 f() { typeset -n foo="$1"; declare -p foo; echo "$foo"; }
8
9 f 'x[$zero]'
10
11 x[$(echo 0)]=4
12 declare -p x
13
14 f 'x[$(echo 0)]'
15
16 unset -f f
17 f()
18 {
19 typeset -n foo="$1";
20
21 echo "x[i=0$(echo comsub >&2)]"
22 echo "${x[i=0$(echo comsub >&2)]}"
23 echo "${!1}"
24 echo "$foo"
25 }
26
27 f 'x[i=0$(echo comsub >&2)]'
28
29 unset -f f
30 unset x
31
32 # problems with unset and namerefs pointing to non-existent variables pointed
33 # out after bash-4.3 released
34
35 typeset -n foo=somevariable
36 foo=bar
37 unset foo # unsets somevariable
38 typeset -p foo somevariable
39 echo foo = $foo
40
41 typeset -A foo # should create array variable named somevariable
42 foo["jug"]="brown"
43
44 typeset -p foo somevariable
45 typeset -A foo='([jug]="brown" )'
46 typeset -p foo somevariable
47
48 unset foo
49 typeset -p foo somevariable
50 unset -n foo
51 typeset -p foo somevariable
52
53 unset bar
54 typeset -n foo=bar
55 typeset -p foo bar
56 unset foo
57 typeset -p foo bar
58 typeset -i foo
59 foo=4+4
60 typeset -p foo bar
61 echo "$foo"
62
63 unset foo
64 typeset -p foo bar