]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/new-exp10.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / new-exp10.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# new framework for parameter transformations, post bash-4.3
15
16printf "<%s>" "${x@Q}" ; echo
17printf "<%s>" "${x@E}" ; echo
18printf "<%s>" "${x@P}" ; echo
19printf "<%s>" "${x@A}" ; echo
20
21x="ab 'cd' ef"
22printf "<%s> " "${x@Q}" ; echo
23
24printf "<%s>" "${x@C}"
25
26# if unquoted, normal word splitting happens
27set -- ab 'cd ef' '' gh
28printf "<%s> " "${@@Q}" ; echo
29printf "<%s> " "${*@Q}" ; echo
30printf "<%s> " ${@@Q} ; echo
31printf "<%s> " ${*@Q} ; echo
32
33y[0]=4
34y[1]='ab cd'
35
36printf "<%s> " "${y[1]@Q}" ; echo
37printf "<%s> " "${y[@]@Q}" ; echo # mksh doesn't like @ or * or arrays subscripted with them
38
39printf "<%s> " "${z@Q}" ; echo # empty string?
40
41recho ${z@Q} # this disappears
42
43#
44HOST=host
45SHELL_LEVEL=2
46NPS1='\[\]${HOST}($SHELL_LEVEL)[\v]\$ '
47
48recho "${NPS1@P}"
49
50#
51D=' \t\n'
52printf "<%s>" "${D@E}" ; echo
53printf "<%s>" "${D@Q}" ; echo
54
55E=$' \t\n'
56printf "<%s>" "${E@E}" ; echo
57printf "<%s>" "${E@Q}" ; echo
58
59declare x
60declare -r x="ab 'cd' ef"
61printf "%s" "${x@A}" ; echo
62
63set -- ab 'cd ef' '' gh
64printf "%s " "${@@A}" ; echo
65
66A=( "$@" )
67printf "%s " "${A[@]@A}" ; echo
68B=()
69printf "%s " "${B[@]@A}" ; echo
70
71unset A
72declare -A A
73A=( [one]=1 [two]='b c' [three]='' [four]=de )
74printf "%s " "${A[@]@A}" ; echo
75
76unset X
77declare X
78declare -r X="ab 'cd' ef"
79printf "%s" "${X@a}" ; echo
80
81set -- 1 2 3 4
82
83unset A
84A=( "$@" )
85printf "%s " "${A@a}" ; echo
86
87unset A
88declare -A A
89A=( [one]=1 [two]='b c' [three]='' [four]=de )
90printf "%s " "${A@a}" ; echo
91
92declare -ir Y=0
93printf "%s" "${Y@a}" ; echo
94
95# make sure we still handle ${#@} and ${@} as posix requires
96set -- a b c d e
97echo ${@}
98echo ${#@}
99echo a${#@}b
d233b485
CR
100
101# new feature in bash-5.0: display attributes of even unset variables
102unset -v foo
103
104declare -i foo
105echo ${foo@a}
106
107declare -p foo
108
109unset foo
110declare -A foo
111echo ${foo@a}
112
113declare -p foo