1 ########################################################################
3 # This software is part of the ast package #
4 # Copyright (c) 1982-2010 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Common Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
9 # A copy of the License is available at #
10 # http://www.opensource.org/licenses/cpl1.0.txt #
11 # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
13 # Information and Software Systems Research #
17 # David Korn <dgk@research.att.com> #
19 ########################################################################
23 print
-u2 -r ${Command}[$1]: "${@:2}"
26 alias err_exit
='err_exit $LINENO'
30 if [[ 'hi there' != "hi there" ]]
31 then err_exit
"single quotes not the same as double quotes"
34 if [[ $x != 'hi there' ]]
35 then err_exit
"$x not the same as 'hi there'"
37 if [[ $x != "hi there" ]]
38 then err_exit
"$x not the same as \"hi there \""
40 if [[ \a\b\c\
*\|
\"\
\\ != 'abc*|" \' ]]
41 then err_exit " \\ differs from '' "
43 if [[ "ab\'\"\$(" != 'ab
\'\''"$(' ]]
44 then err_exit
" \"\" differs from '' "
46 if [[ $
(print
-r - 'abc*|" \') != 'abc
*|
" \' ]]
47 then err_exit "\$
(print
-r - '') differs from
''"
49 if [[ $(print -r - "abc
*|
\" \\") != 'abc*|" \' ]]
50 then err_exit
"\$(print -r - '') differs from ''"
52 if [[ "$(print -r - 'abc*|" \')" != 'abc*|" \' ]]
53 then err_exit
"\"\$(print -r - '')\" differs from ''"
55 if [[ "$(print -r - "abc
*|
\" \\")" != 'abc*|" \' ]]
56 then err_exit "\"\$(print -r - "")\" differs from ''"
58 if [[ $(print -r - $(print -r - 'abc
*|
" \')) != 'abc*|" \' ]]
59 then err_exit
"nested \$(print -r - '') differs from ''"
61 if [[ "$(print -r - $(print -r - 'abc*|" \'))" != 'abc*|" \' ]]
62 then err_exit
"\"nested \$(print -r - '')\" differs from ''"
64 if [[ $
(print
-r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]]
65 then err_exit
"nested \"\$(print -r - '')\" differs from ''"
68 if [[ ${x-$(print -r - "abc*|\" \\")} != 'abc*|" \' ]]
69 then err_exit "\${x-\$(print -r - '')} differs from ''"
71 if [[ ${x-$(print -r - "a}c*|\" \\")} != 'a
}c
*|
" \' ]]
72 then err_exit "\
${x-\$(print -r - '}')} differs from ''"
76 then err_exit "((cmd)|(cmd)) failed"
78 x=$(print -r -- "\"$HOME\"")
79 if [[ $x != '"'$HOME'"' ]]
80 then err_exit "nested double quotes failed"
83 if [[ $z != 'a
{b
}c
' ]]
84 then err_exit '${z="a{b}c
"} not correct'
88 if [[ $z != 'a{b}c' ]]
89 then err_exit
'"${z="a{b}c"}" not correct'
91 if [[ $
(print
-r -- "a\*b") != 'a\*b' ]]
92 then err_exit
'$(print -r -- "a\*b") differs from a\*b'
95 if [[ $
(print
-r -- "a\*b$x") != 'a\*b' ]]
96 then err_exit
'$(print -r -- "a\*b$x") differs from a\*b'
99 set -- ${x+foo bar bam}
101 then err_exit
'${x+foo bar bam} does not yield three arguments'
103 set -- ${x+foo "bar bam"}
105 then err_exit
'${x+foo "bar bam"} does not yield two arguments'
107 set -- ${x+foo 'bar bam'}
109 then err_exit
'${x+foo '\''bar bam'\''} does not yield two arguments'
111 set -- ${x+foo $x bam}
113 then err_exit
'${x+foo $x bam} does not yield three arguments'
115 set -- ${x+foo "$x" bam}
117 then err_exit
'${x+foo "$x" bam} does not yield three arguments'
119 set -- ${x+"foo $x bam"}
121 then err_exit
'${x+"foo $x bam"} does not yield one argument'
123 set -- "${x+foo $x bam}"
125 then err_exit
'"${x+foo $x bam}" does not yield one argument'
127 set -- ${x+foo "$x "bam}
129 then err_exit
'${x+foo "$x "bam} does not yield two arguments'
132 if [[ $x != 'ab$'"'cd" ]]
133 then err_exit
'$'"' inside double quotes not working"
137 then err_exit
'$'"' inside `` quotes not working"
144 then err_exit
'line continuation in double strings not working'
150 then err_exit
'line continuation in expanded double strings not working'
153 if [[ $
(print
-r -- $x) != '\*' ]]
154 then err_exit
'x="\\*";$x != \*'
159 then err_exit
'field splitting error'
161 x
=$
(print
-r -- '1234567890123456789012345678901234567890123456789012345678901234567890 \
162 1234567890123456789012345678901234567890123456789012345678901234567890 \
163 1234567890123456789012345678901234567890123456789012345678901234567890 \
164 1234567890123456789012345678901234567890123456789012345678901234567890 \
165 1234567890123456789012345678901234567890123456789012345678901234567890 \
166 1234567890123456789012345678901234567890123456789012345678901234567890 \
167 1234567890123456789012345678901234567890123456789012345678901234567890 \
168 1234567890123456789012345678901234567890123456789012345678901234567890 \
169 1234567890123456789012345678901234567890123456789012345678901234567890 \
170 1234567890123456789012345678901234567890123456789012345678901234567890 \
171 1234567890123456789012345678901234567890123456789012345678901234567890 \
172 1234567890123456789012345678901234567890123456789012345678901234567890 \
173 1234567890123456789012345678901234567890123456789012345678901234567890 \
174 1234567890123456789012345678901234567890123456789012345678901234567890 \
175 1234567890123456789012345678901234567890123456789012345678901234567890')
176 if (( ${#x} != (15*73-3) ))
177 then err_exit
"length of x, ${#x}, is incorrect should be $((15*73-3))"
180 if [[ $x\$
!= '$hi$' ]]
181 then err_exit
' $x\$, with x=$hi, does not expand to $hi$'
183 if [[ $x$
!= '$hi$' ]]
184 then err_exit
' $x$, with x=$hi, does not expand to $hi$'
186 set -- $
(/bin
/echo foo
;sleep 1;/bin
/echo bar
)
188 then err_exit
'word splitting after command substitution not working'
191 if [[ "${q:+'}q${q:+'}" != q
]]
192 then err_exit
'expansion of "{q:+'\''}" not correct when q unset'
195 if [[ "${q:+'}q${q:+'}" != "'q'" ]]
196 then err_exit
'expansion of "{q:+'\''}" not correct when q set'
199 if [[ $x != "x' #y" ]]
200 then err_exit
"$'x\' #y'" not working
203 if [[ $x != "1x' #y" ]]
204 then err_exit
"$q$'x\' #y'" not working
210 then err_exit "field splitting of $x with IFS=$IFS not working"
213 bar=$(print -r -- ${foo+\\n\ })
214 if [[ $bar != '\n ' ]]
215 then err_exit '${foo+\\n\ } expansion error
'
218 bar=$(print -r -- ${foo+\\n\ $bar})
219 if [[ $bar != '\n ' ]]
220 then err_exit '${foo+\\n\ $bar} expansion error with bar
unset'
222 x='\\(..
\\)|
&\|\|
\\&\\|
'
223 if [[ $(print -r -- $x) != "$x" ]]
224 then err_exit '$x, where x
=\\(..
\\)|
&\|\|
\\&\\| not working
'
227 if [[ $(print -r -- a${x}b) != a"${x}"b ]]
228 then err_exit 'a
${x}b
, where x
=\\( not working
'
231 if [[ $(print -r -- $x'\\1') != '\\1' ]]
232 then err_exit 'backreference inside single quotes broken
'
237 then err_exit '"$@" not preserving nulls
'
240 if [[ $(print -r s"!\2${x}\1\a!") != 's
!\
2\
1\a!' ]]
241 then err_exit 'print
-r s
"!\2${x}\1\a!" not equal s
!\
2\
1\a!'
243 if [[ $(print -r $'foo
\n\n\n') != foo ]]
244 then err_exit 'trailing newlines on comsubstitution not removed
'
247 if [[ ${x:='//'} != '//' ]]
248 then err_exit '${x:='//'} != "//"'
250 if [[ $(print -r "\"hi$\"") != '"hi$"' ]]
251 then err_exit '$\ not correct inside
""'
254 if [[ "${x-a\}b}" != 'a
}b
' ]]
255 then err_exit '"${x-a\}b}" != "a}b"'
257 if [[ "\}\]$x\*\{\[\\" != '\
}\
]\
*\
{\
[\' ]]
258 then err_exit
'"\}\]$x\*\{\[\\" != "\}\]\*\{\[\"'
261 if [[ $
(print
-r -- {\
$foo}) != '{$foo}' ]]
262 then err_exit
'{\$foo}' not expanded correctly
265 ###########################################################
266 ###########################################################
267 ###########################################################
268 ###########################################################
269 ###########################################################
270 ###########################################################
271 ###########################################################
272 ###########################################################
273 ###########################################################
274 ###########################################################
275 ###########################################################
276 ###########################################################
277 ###########################################################
278 ###########################################################
279 ###########################################################
280 ###########################################################
281 ###########################################################
282 ###########################################################
283 ###########################################################
284 ###########################################################
285 ###########################################################
286 ###########################################################
287 ###########################################################
288 ###########################################################
289 ###########################################################
290 ###########################################################
291 ###########################################################
292 ###########################################################
293 ###########################################################
294 ###########################################################
295 ###########################################################
296 ###########################################################
297 ###########################################################
298 ###########################################################
299 ###########################################################
300 ###########################################################
301 ###########################################################
302 ###########################################################
303 print foo
) ]] || err_exit
"command subsitution with long comments broken"
304 subject
='some/other/words'
306 [[ ${subject/${re}/\3} != words
]] && err_exit
'string replacement with \3 not working'
307 [[ ${subject/${re}/'\3'} != '\3' ]] && err_exit
'string replacement with '"'\3'"' not working'
308 [[ ${subject/${re}/"\\3"} != '\3' ]] && err_exit
'string replacement with "\\3" not working'
309 [[ ${subject/${re}/"\3"} != '\3' ]] && err_exit
'string replacement with "\3" not working'
311 [[ ${subject/${re}/${string}} != words
]] && err_exit
'string replacement with $string not working with string=\3'
312 [[ $
(print
-r "${subject/${re}/${string}}") != words
]] && err_exit
'string replacement with $string not working with string=\3 using print'
313 [[ ${subject/${re}/"${string}"} != '\3' ]] && err_exit
'string replacement with "$string" not working with string=\3'
314 [[ $
(print
-r "${subject/${re}/"${string}"}") != '\3' ]] && err_exit
'string replacement with "$string" not working with string=\3 using print'
316 [[ ${subject/${re}/${string}} != '\3' ]] && err_exit
'string replacement with $string not working with string=\\3'
317 [[ ${subject/${re}/"${string}"} != '\\3' ]] && err_exit
'string replacement with "$string" not working with string=\\3'
318 [[ ${subject/${re}/\4} != '\4' ]] && err_exit
'string replacement with \4 not working'
319 [[ ${subject/${re}/'\4'} != '\4' ]] && err_exit
'string replacement with '\
4' not working'
321 [[ ${subject/${re}/${string}} != '\4' ]] && err_exit
'string replacement with $string not working with string=\4'
322 [[ ${subject/${re}/"${string}"} != '\4' ]] && err_exit
'string replacement with "$string" not working with string=\4'
324 [[ ${subject/${re}/${string}} != '&foo' ]] && err_exit
'string replacement with $string not working with string=&foo'
325 [[ ${subject/${re}/"${string}"} != '&foo' ]] && err_exit
'string replacement with "$string" not working with string=&foo'
328 x
=${x:-`id | sed 's/^[^(]*(\([^)]*\)).*/\1/'`}
329 } 2> /dev
/null || err_exit
'skipping over `` failed'
330 [[ $x == x
]] || err_exit
'assignment ${x:=`...`} failed'
331 [[ $
($SHELL -c 'print a[') == 'a[' ]] || err_exit
"unbalanced '[' in command arg fails"
332 $SHELL -c $
'false && (( `wc -l /dev/null | nawk \'{print $1}\'` > 2 )) && true;:' 2> /dev
/null || err_exit
'syntax error with ` in arithmetic expression'
333 { $SHELL -c '(( 1`: "{ }"` ))' ;} 2> /dev
/null || err_exit
'problem with ` inside (())'
335 x
=`print '"\$'${varname}'"'`
336 [[ $x == '"$foobarx"' ]] || err_exit $
'\\$\' not handled correctly inside ``'
339 foo
="`eval echo "$
"{copy$copynum"-0}"`"
340 [[ $foo == "$copy1" ]] || err_exit
'$"..." not being ignored inside ``'