File: new-exp10.sub

package info (click to toggle)
bash 5.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 43,860 kB
  • sloc: ansic: 134,738; sh: 8,866; yacc: 5,966; makefile: 4,697; perl: 4,105; asm: 48; awk: 23; sed: 16
file content (153 lines) | stat: -rw-r--r-- 3,166 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# new framework for parameter transformations, post bash-4.3

printf "<%s>" "${x@Q}" ; echo
printf "<%s>" "${x@E}" ; echo
printf "<%s>" "${x@P}" ; echo
printf "<%s>" "${x@A}" ; echo

x="ab 'cd' ef"
printf "<%s> " "${x@Q}" ; echo 

# this needs to be run in a subshell because invalid transformation operators
# are now treated as substitution errors, fatal in non-interactive shells
${THIS_SH} -c 'x=abcdef ; printf "<%s>" "${x@C}"' bash

# if unquoted, normal word splitting happens
set -- ab 'cd ef' '' gh
printf "<%s> " "${@@Q}" ; echo
printf "<%s> " "${*@Q}" ; echo
printf "<%s> " ${@@Q} ; echo
printf "<%s> " ${*@Q} ; echo

y[0]=4
y[1]='ab cd'

printf "<%s> " "${y[1]@Q}" ; echo
printf "<%s> " "${y[@]@Q}" ; echo	# mksh doesn't like @ or * or arrays subscripted with them

printf "<%s> " "${z@Q}"	; echo	# empty string?

recho ${z@Q}		# this disappears

#
D=' \t\n'
printf "<%s>" "${D@E}" ; echo
printf "<%s>" "${D@Q}" ; echo

E=$' \t\n'
printf "<%s>" "${E@E}" ; echo
printf "<%s>" "${E@Q}" ; echo

v=$'\1\1'
printf '%q\n' "${v@E}"
unset -v v

declare x
declare -r x="ab 'cd' ef"
printf "%s" "${x@A}" ; echo 

set -- ab 'cd ef' '' gh
printf "%s " "${@@A}" ; echo

A=( "$@" )
printf "%s " "${A[@]@A}" ; echo
B=()
printf "%s " "${B[@]@A}" ; echo

unset A
declare -A A
A=( [one]=1 [two]='b c' [three]='' [four]=de )
printf "%s " "${A[@]@A}" ; echo

unset X
declare X
declare -r X="ab 'cd' ef"
printf "%s" "${X@a}" ; echo 

set -- 1 2 3 4

unset A
A=( "$@" )
printf "%s " "${A@a}" ; echo

unset A
declare -A A
A=( [one]=1 [two]='b c' [three]='' [four]=de )
printf "%s " "${A@a}" ; echo

declare -ir Y=0
printf "%s" "${Y@a}" ; echo 

# make sure we still handle ${#@} and ${@} as posix requires
set -- a b c d e
echo ${@}
echo ${#@}
echo a${#@}b

# new feature in bash-5.0: display attributes of even unset variables
unset -v foo

declare -i foo
echo ${foo@a}

declare -p foo

unset foo
declare -A foo
echo ${foo@a}

declare -p foo

unset -v foo
foo=lower
echo ${foo@U}
echo ${foo@u}

# framework for testing prompt expansions using @P transformation
cd /tmp

HOST=host
SHELL_LEVEL=2
HOME=$PWD

NPS1='\[\]${HOST}($SHELL_LEVEL)[\v]\$ '
recho "${NPS1@P}"

NPS1='\[\]\W\$\040'
recho "${NPS1@P}"

NPS1='\[\001\][\j]\w\$\040'
recho "${NPS1@P}"

NPS1='\[\a\][\j:\!]\w\\\$\040'
set -o emacs
recho "${NPS1@P}"
set +o emacs

cd /
# no longer abbreviate as ~
NPS1='\W \s\$\040'
recho "${NPS1@P}"

set -o posix
NPS1='!\n\W \s\$\040'
recho "${NPS1@P}"

cd $OLDPWD

# this must be last, fatal error
V=42
echo ${V@}	# error