summaryrefslogtreecommitdiff
path: root/tests/comsub2.tests
blob: 0254d8db4049f5c7f2fad9ef67fcfd019f1ece29 (plain)
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
#   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 ${ typeset x; printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; }
echo outside: $x
xx=${ typeset x; printf '%s\n' aa bb cc dd; x=42 ; return 12; echo ee ff; }
echo assignment: $?
unset xx

echo ${( echo abcde )}		# works in ksh93

echo ${| echo 67890;  REPLY=12345; }		# works in mksh

# 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
echo "${ typeset x;
	for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done
 	x=42 ; return; echo this should not be seen; }"
echo outside: $x
shopt expand_aliases

set -o posix
echo "${ typeset x;
	for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done
 	x=42 ; return; echo this should not be seen; }"
echo outside: $x
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)}"
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