File: comsub2.tests

package info (click to toggle)
bash 5.3-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 44,432 kB
  • sloc: ansic: 134,747; 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,830 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/>.
#

# initial set of tests for ${Ccommand; } nofork command substitution

# basic functionality

echo ${ printf '%s\n' aa bb cc dd; }
echo AA${ printf '%s\n' aa bb cc dd; }BB

echo ${ printf '%s\n' aa bb cc dd; return; echo ee ff; }
echo ${ printf '%s\n' aa bb cc dd
	}
echo DDDDD${
	printf '%s\n' aa bb cc dd
}EEEEE
unset x
echo ${ printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; }
echo outside: $x
unset x
echo ${ local x; printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; }
echo outside: $x
xx=${ local x; printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; }
echo assignment: $?
unset xx

declare -i x
y=${ :;}
declare -i z
unset -v x y z

# variables can be local, but all function declarations are global
func() { echo func-outside; }
xx=${ func() { echo func-inside; }; }
declare -f func
xx=${ unset -f func; }
declare -f func

echo ${ ( echo abcde );}

echo ${| echo 67890;  REPLY=12345; }		# works in mksh
x=${| REPLY= ;}
recho "$x"
unset x
x=${| :;}
recho "$x"
unset x

echo ${ echo aa; },${ echo bb; }

# basic job control
set -m
echo this should disappear | echo JOB${ printf '%s\n' aa bb cc dd; }CONTROL | cat
set +m

# command not found should still echo error messages to stderr
echo NOT${ p; }FOUND

# alias handling in command substitutions, default and posix mode
alias p=printf
alias e='echo aliasval'
echo "${ typeset x;
	for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done
	unalias p
	alias e='echo inside redefine'
 	x=42 ; return; echo this should not be seen; }"
echo outside: $x
alias p e
shopt expand_aliases

alias p=printf
set -o posix
echo "${ typeset x;
	for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done
	unalias p;
 	x=42 ; return; echo this should not be seen; }"
echo outside: $x
alias p
shopt expand_aliases

set +o posix

shopt -s expand_aliases

alias p=printf
echo "${ typeset x;
	for f in 1 2; do p '%s\n' $f ; /bin/echo xx ; shopt expand_aliases; done
 	x=42 ; return; echo ee ff; }"
echo outside: $x
shopt expand_aliases

# more tests for value substitutions and local variables
a=1 b=2
a=${| local b ; a=12 ; b=22 ; REPLY=42 ; echo inside: $a $b $REPLY; }
echo outside: $a $b
unset a b

# this form doesn't remove the trailing newlines
REPLY=42
a=${| REPLY=$'newlines\n\n'; }
echo "$a"
echo outside: $REPLY

# how do we handle shift with these weird ksh93 function-like semantics?
# ksh93 doesn't reset the positional parameters here
set -- 1 2
echo before: "$@"
: "${ shift;}"
echo after: "$@"

set -- 1 2
echo before: "$@"
: "${| shift;}"
echo after: "$@"

set -- 1 2
echo before: "$@"
: "${ ( shift) }"	# parse_comsub adds the closing semicolon anyway
echo after: "$@"

# nested funsubs
echo ${ echo X${ echo nested; }Y; }
echo ${ echo a ; echo ${ echo nested; }; echo b; }

# nested funsubs/comsubs
x=${
	echo ${ echo one;} $(echo two)
}
echo $x

# mixing funsubs and arithmetic expansion
echo $(( ${ echo 24 + 18; }))
echo $(( ${ echo 14 + 18; }+ 10))
echo ${ echo $(( 24+18 )); }

# alias expansion and nested funsubs in other constructs
${THIS_SH} ./comsub21.sub
${THIS_SH} ./comsub22.sub
${THIS_SH} ./comsub23.sub
${THIS_SH} ./comsub24.sub
${THIS_SH} ./comsub25.sub
${THIS_SH} ./comsub26.sub