14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 1982-2010 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 78462SApril.Chin@Sun.COM# by AT&T Intellectual Property # 84887Schin# # 94887Schin# A copy of the License is available at # 104887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 114887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 124887Schin# # 134887Schin# Information and Software Systems Research # 144887Schin# AT&T Research # 154887Schin# Florham Park NJ # 164887Schin# # 174887Schin# David Korn <dgk@research.att.com> # 184887Schin# # 194887Schin######################################################################## 204887Schinfunction err_exit 214887Schin{ 224887Schin print -u2 -n "\t" 234887Schin print -u2 -r ${Command}[$1]: "${@:2}" 244887Schin let Errors+=1 254887Schin} 264887Schinalias err_exit='err_exit $LINENO' 274887Schin 284887SchinCommand=${0##*/} 294887Schininteger Errors=0 j=4 304887Schinbase=/home/dgk/foo//bar 314887Schinstring1=$base/abcabcabc 324887Schinif [[ ${string1:0} != "$string1" ]] 334887Schinthen err_exit "string1:0" 344887Schinfi 354887Schinif [[ ${string1: -1} != "c" ]] 364887Schinthen err_exit "string1: -1" 374887Schinfi 384887Schinif [[ ${string1:0:1000} != "$string1" ]] 394887Schinthen err_exit "string1:0" 404887Schinfi 414887Schinif [[ ${string1:1} != "${string1#?}" ]] 424887Schinthen err_exit "string1:1" 434887Schinfi 444887Schinif [[ ${string1:1:4} != home ]] 454887Schinthen err_exit "string1:1:4" 464887Schinfi 474887Schinif [[ ${string1: -5:4} != bcab ]] 484887Schinthen err_exit "string1: -5:4" 494887Schinfi 504887Schinif [[ ${string1:1:j} != home ]] 514887Schinthen err_exit "string1:1:j" 524887Schinfi 534887Schinif [[ ${string1:(j?1:0):j} != home ]] 544887Schinthen err_exit "string1:(j?1:0):j" 554887Schinfi 564887Schinif [[ ${string1%*zzz*} != "$string1" ]] 574887Schinthen err_exit "string1%*zzz*" 584887Schinfi 594887Schinif [[ ${string1%%*zzz*} != "$string1" ]] 604887Schinthen err_exit "string1%%*zzz*" 614887Schinfi 624887Schinif [[ ${string1#*zzz*} != "$string1" ]] 634887Schinthen err_exit "string1#*zzz*" 644887Schinfi 654887Schinif [[ ${string1##*zzz*} != "$string1" ]] 664887Schinthen err_exit "string1##*zzz*" 674887Schinfi 684887Schinif [[ ${string1%+(abc)} != "$base/abcabc" ]] 694887Schinthen err_exit "string1%+(abc)" 704887Schinfi 714887Schinif [[ ${string1%%+(abc)} != "$base/" ]] 724887Schinthen err_exit "string1%%+(abc)" 734887Schinfi 744887Schinif [[ ${string1%/*} != "$base" ]] 754887Schinthen err_exit "string1%/*" 764887Schinfi 774887Schinif [[ "${string1%/*}" != "$base" ]] 784887Schinthen err_exit '"string1%/*"' 794887Schinfi 804887Schinif [[ ${string1%"/*"} != "$string1" ]] 814887Schinthen err_exit 'string1%"/*"' 824887Schinfi 834887Schinif [[ ${string1%%/*} != "" ]] 844887Schinthen err_exit "string1%%/*" 854887Schinfi 864887Schinif [[ ${string1#*/bar} != /abcabcabc ]] 874887Schinthen err_exit "string1#*bar" 884887Schinfi 894887Schinif [[ ${string1##*/bar} != /abcabcabc ]] 904887Schinthen err_exit "string1#*bar" 914887Schinfi 924887Schinif [[ "${string1#@(*/bar|*/foo)}" != //bar/abcabcabc ]] 934887Schinthen err_exit "string1#@(*/bar|*/foo)" 944887Schinfi 954887Schinif [[ ${string1##@(*/bar|*/foo)} != /abcabcabc ]] 964887Schinthen err_exit "string1##@(*/bar|*/foo)" 974887Schinfi 984887Schinif [[ ${string1##*/@(bar|foo)} != /abcabcabc ]] 994887Schinthen err_exit "string1##*/@(bar|foo)" 1004887Schinfi 1014887Schinfoo=abc 1024887Schinif [[ ${foo#a[b*} != abc ]] 1034887Schinthen err_exit "abc#a[b*} != abc" 1044887Schinfi 1054887Schinif [[ ${foo//[0-9]/bar} != abc ]] 1064887Schinthen err_exit '${foo//[0-9]/bar} not expanding correctly' 1074887Schinfi 1084887Schinfoo='(abc)' 1094887Schinif [[ ${foo#'('} != 'abc)' ]] 1104887Schinthen err_exit "(abc)#( != abc)" 1114887Schinfi 1124887Schinif [[ ${foo%')'} != '(abc' ]] 1134887Schinthen err_exit "(abc)%) != (abc" 1144887Schinfi 1154887Schinfoo=a123b456c 1164887Schinif [[ ${foo/[0-9]?/""} != a3b456c ]] 1174887Schinthen err_exit '${foo/[0-9]?/""} not expanding correctly' 1184887Schinfi 1194887Schinif [[ ${foo//[0-9]/""} != abc ]] 1204887Schinthen err_exit '${foo//[0-9]/""} not expanding correctly' 1214887Schinfi 1224887Schinif [[ ${foo/#a/b} != b123b456c ]] 1234887Schinthen err_exit '${foo/#a/b} not expanding correctly' 1244887Schinfi 1254887Schinif [[ ${foo/#?/b} != b123b456c ]] 1264887Schinthen err_exit '${foo/#?/b} not expanding correctly' 1274887Schinfi 1284887Schinif [[ ${foo/%c/b} != a123b456b ]] 1294887Schinthen err_exit '${foo/%c/b} not expanding correctly' 1304887Schinfi 1314887Schinif [[ ${foo/%?/b} != a123b456b ]] 1324887Schinthen err_exit '${foo/%?/b} not expanding correctly' 1334887Schinfi 1344887Schinwhile read -r pattern string expected 1354887Schindo if (( expected )) 1364887Schin then if [[ $string != $pattern ]] 1374887Schin then err_exit "$pattern does not match $string" 1384887Schin fi 1394887Schin if [[ ${string##$pattern} != "" ]] 1404887Schin then err_exit "\${$string##$pattern} not null" 1414887Schin fi 1424887Schin if [ "${string##$pattern}" != '' ] 1434887Schin then err_exit "\"\${$string##$pattern}\" not null" 1444887Schin fi 1454887Schin if [[ ${string/$pattern} != "" ]] 1464887Schin then err_exit "\${$string/$pattern} not null" 1474887Schin fi 1484887Schin else if [[ $string == $pattern ]] 1494887Schin then err_exit "$pattern matches $string" 1504887Schin fi 1514887Schin fi 1524887Schindone <<- \EOF 1534887Schin +(a)*+(a) aabca 1 1544887Schin !(*.o) foo.o 0 1554887Schin !(*.o) foo.c 1 1564887SchinEOF 1574887Schinxx=a/b/c/d/e 1584887Schinyy=${xx#*/} 1594887Schinif [[ $yy != b/c/d/e ]] 1604887Schinthen err_exit '${xx#*/} != a/b/c/d/e when xx=a/b/c/d/e' 1614887Schinfi 1624887Schinif [[ ${xx//\//\\} != 'a\b\c\d\e' ]] 1634887Schinthen err_exit '${xx//\//\\} not working' 1644887Schinfi 1654887Schinx=[123]def 1664887Schinif [[ "${x//\[(*)\]/\{\1\}}" != {123}def ]] 1674887Schinthen err_exit 'closing brace escape not working' 1684887Schinfi 1698462SApril.Chin@Sun.COMxx=%28text%29 1708462SApril.Chin@Sun.COMif [[ ${xx//%28/abc\)} != 'abc)text%29' ]] 1718462SApril.Chin@Sun.COMthen err_exit '${xx//%28/abc\)} not working' 1728462SApril.Chin@Sun.COMfi 1738462SApril.Chin@Sun.COMxx='a:b' 1748462SApril.Chin@Sun.COMstr='(){}[]*?|&^%$#@l' 1758462SApril.Chin@Sun.COMfor ((i=0 ; i < ${#str}; i++)) 1768462SApril.Chin@Sun.COMdo [[ $(eval print -r -- \"\${xx//:/\\${str:i:1}}\") == "a${str:i:1}b" ]] || err_exit "substitution of \\${str:i:1}} failed" 1778462SApril.Chin@Sun.COM [[ $(eval print -rn -- \"\${xx//:/\'${str:i:1}\'}\") == "a${str:i:1}b" ]] || err_exit "substitution of '${str:i:1}' failed" 1788462SApril.Chin@Sun.COM [[ $(eval print -r -- \"\${xx//:/\"${str:i:1}\"}\") == "a${str:i:1}b" ]] || err_exit "substitution of \"${str:i:1}\" failed" 1798462SApril.Chin@Sun.COMdone 1808462SApril.Chin@Sun.COM[[ ${xx//:/\\n} == 'a\nb' ]] || err_exit "substituion of \\\\n failed" 1818462SApril.Chin@Sun.COM[[ ${xx//:/'\n'} == 'a\nb' ]] || err_exit "substituion of '\\n' failed" 1828462SApril.Chin@Sun.COM[[ ${xx//:/"\n"} == 'a\nb' ]] || err_exit "substituion of \"\\n\" failed" 1838462SApril.Chin@Sun.COM[[ ${xx//:/$'\n'} == $'a\nb' ]] || err_exit "substituion of \$'\\n' failed" 1844887Schinunset foo 1854887Schinfoo=one/two/three 1864887Schinif [[ ${foo//'/'/_} != one_two_three ]] 1874887Schinthen err_exit 'single quoting / in replacements failed' 1884887Schinfi 1894887Schinif [[ ${foo//"/"/_} != one_two_three ]] 1904887Schinthen err_exit 'double quoting / in replacements failed' 1914887Schinfi 1924887Schinif [[ ${foo//\//_} != one_two_three ]] 1934887Schinthen err_exit 'escaping / in replacements failed' 1944887Schinfi 19510898Sroland.mainz@nrubsig.orgfunction myexport 1964887Schin{ 1974887Schin nameref var=$1 1984887Schin if (( $# > 1 )) 1994887Schin then export $1=$2 2004887Schin fi 2014887Schin if (( $# > 2 )) 2024887Schin then print $(myexport "$1" "$3" ) 2034887Schin return 2044887Schin fi 2054887Schin typeset val 2064887Schin val=$(export | grep "^$1=") 2074887Schin print ${val#"$1="} 20810898Sroland.mainz@nrubsig.org 2094887Schin} 2104887Schinexport dgk=base 2114887Schinif [[ $(myexport dgk fun) != fun ]] 2124887Schinthen err_exit 'export inside function not working' 2134887Schinfi 2144887Schinval=$(export | grep "^dgk=") 2154887Schinif [[ ${val#dgk=} != base ]] 2164887Schinthen err_exit 'export not restored after function call' 2174887Schinfi 2184887Schinif [[ $(myexport dgk fun fun2) != fun2 ]] 2194887Schinthen err_exit 'export inside function not working with recursive function' 2204887Schinfi 2214887Schinval=$(export | grep "^dgk=") 2224887Schinif [[ ${val#dgk=} != base ]] 2234887Schinthen err_exit 'export not restored after recursive function call' 2244887Schinfi 2254887Schinif [[ $(dgk=try3 myexport dgk) != try3 ]] 2264887Schinthen err_exit 'name=value not added to export list with function call' 2274887Schinfi 2284887Schinval=$(export | grep "^dgk=") 2294887Schinif [[ ${val#dgk=} != base ]] 2304887Schinthen err_exit 'export not restored name=value function call' 2314887Schinfi 2324887Schinunset zzz 2334887Schinif [[ $(myexport zzz fun) != fun ]] 2344887Schinthen err_exit 'export inside function not working for zzz' 2354887Schinfi 2364887Schinif [[ $(export | grep "zzz=") ]] 2374887Schinthen err_exit 'zzz exported after function call' 2384887Schinfi 2394887Schinset -- foo/bar bam/yes last/file/done 2404887Schinif [[ ${@/*\/@(*)/${.sh.match[1]}} != 'bar yes done' ]] 2414887Schinthen err_exit '.sh.match not working with $@' 2424887Schinfi 2434887Schinif [[ ${@/*\/@(*)/\1} != 'bar yes done' ]] 2444887Schinthen err_exit '\1 not working with $@' 2454887Schinfi 2464887Schinvar=(foo/bar bam/yes last/file/done) 2474887Schinif [[ ${var[@]/*\/@(*)/${.sh.match[1]}} != 'bar yes done' ]] 2484887Schinthen err_exit '.sh.match not working with ${var[@]}' 2494887Schinfi 2504887Schinif [[ ${var[@]/*\/@(*)/\1} != 'bar yes done' ]] 2514887Schinthen err_exit '\1 not working with ${var[@]}' 2524887Schinfi 2534887Schinvar='abc_d2ef.462abc %%' 2544887Schinif [[ ${var/+(\w)/Q} != 'Q.462abc %%' ]] 2554887Schinthen err_exit '${var/+(\w)/Q} not workding' 2564887Schinfi 2574887Schinif [[ ${var//+(\w)/Q} != 'Q.Q %%' ]] 2584887Schinthen err_exit '${var//+(\w)/Q} not workding' 2594887Schinfi 2604887Schinif [[ ${var//+(\S)/Q} != 'Q Q' ]] 2614887Schinthen err_exit '${var//+(\S)/Q} not workding' 2624887Schinfi 2634887Schinfoo='foo+bar+' 2644887Schin[[ $(print -r -- ${foo//+/'|'}) != 'foo|bar|' ]] && err_exit "\${foobar//+/'|'}" 2654887Schin[[ $(print -r -- ${foo//+/"|"}) != 'foo|bar|' ]] && err_exit '${foobar//+/"|"}' 2664887Schin[[ $(print -r -- "${foo//+/'|'}") != 'foo|bar|' ]] && err_exit '"${foobar//+/'"'|'"'}"' 2674887Schin[[ $(print -r -- "${foo//+/"|"}") != 'foo|bar|' ]] && err_exit '"${foobar//+/"|"}"' 2684887Schinunset x 2694887Schinx=abcedfg 2704887Schin: ${x%@(d)f@(g)} 2714887Schin[[ ${.sh.match[0]} == dfg ]] || err_exit '.sh.match[0] not dfg' 2724887Schin[[ ${.sh.match[1]} == d ]] || err_exit '.sh.match[1] not d' 2734887Schin[[ ${.sh.match[2]} == g ]] || err_exit '.sh.match[2] not g' 2744887Schinx=abcedddfg 2754887Schin: ${x%%+(d)f@(g)} 2764887Schin[[ ${.sh.match[1]} == ddd ]] || err_exit '.sh.match[1] not ddd' 2774887Schinunset a b 2784887Schina='\[abc @(*) def\]' 2794887Schinb='[abc 123 def]' 2804887Schin[[ ${b//$a/\1} == 123 ]] || err_exit "\${var/pattern} not working with \[ in pattern" 2818462SApril.Chin@Sun.COMunset foo 2828462SApril.Chin@Sun.COMfoo='(win32.i386) ' 28310898Sroland.mainz@nrubsig.org[[ ${foo/'('/'(x11-'} == '(x11-win32.i386) ' ]] || err_exit "\${var/pattern} not working with ' in pattern" 2848462SApril.Chin@Sun.COM$SHELL -c $'v=\'$(hello)\'; [[ ${v//\'$(\'/-I\'$(\'} == -I"$v" ]]' 2> /dev/null || err_exit "\${var/pattern} not working with \$( as pattern" 2854887Schinunset X 2864887Schin$SHELL -c '[[ ! ${X[@]:0:300} ]]' 2> /dev/null || err_exit '${X[@]:0:300} with X undefined fails' 2874887Schin$SHELL -c '[[ ${@:0:300} == "$0" ]]' 2> /dev/null || err_exit '${@:0:300} with no arguments fails' 2884887Schini=20030704 2894887Schin[[ ${i#{6}(?)} == 04 ]] || err_exit '${i#{6}(?)} not working' 2904887Schin[[ ${i#{6,6}(?)} == 04 ]] || err_exit '${i#{6,6}(?)} not working' 2914887SchinLC_ALL=posix 2924887Schini=" ." 2934887Schin[[ $(printf "<%s>\n" ${i#' '}) == '<.>' ]] || err_exit 'printf "<%s>\n" ${i#' '} failed' 2944887Schinunset x 2954887Schinx=foo 2964887Schin[[ "${x%o}(1)" == "fo(1)" ]] || err_exit 'print ${}() treated as pattern' 2974887Schinunset i pattern string 2984887Schinstring=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz 2994887Schininteger i 3004887Schinfor((i=0; i < ${#string}; i++)) 3014887Schindo pattern+='@(?)' 3024887Schindone 3034887Schin[[ $(string=$string $SHELL -c ": \${string/$pattern/}; print \${.sh.match[26]}") == Z ]] || err_exit -u2 'sh.match[26] not Z' 3044887Schin: ${string/$pattern/} 3054887Schin(( ${#.sh.match[@]} == 53 )) || err_exit '.sh.match has wrong number of elements' 30610898Sroland.mainz@nrubsig.org[[ ${.sh.match[@]:2:4} == 'B C D E' ]] || err_exit '${.sh.match[@]:2:4} incorrect' 3074887Schin 3084887SchinD=$';' E=$'\\\\' Q=$'"' S=$'\'' M='nested pattern substitution failed' 3094887Schin 3104887Schinx='-(-)-' 3114887Schin[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M 3124887Schinx='-(-)-)-' 3134887Schin[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M 3144887Schinx='-(-()-)-' 3154887Schin[[ ${x/*%(())*/\1} == '()' ]] || err_exit $M 3164887Schinx='-(-\)-)-' 3174887Schin[[ ${x/*%(())*/\1} == '(-\)' ]] || err_exit $M 3184887Schinx='-(-\\)-)-' 3194887Schin[[ ${x/*%(())*/\1} == '(-\\)' ]] || err_exit $M 3204887Schinx='-(-(-)-' 3214887Schin[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M 3224887Schinx='-(-(-)-)-' 3234887Schin[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M 3244887Schinx='-(-[-]-)-' 3254887Schin[[ ${x/*%(()[])*/\1} == '(-[-]-)' ]] || err_exit $M 3264887Schinx='-[-(-)-]-' 3274887Schin[[ ${x/*%(()[])*/\1} == '(-)' ]] || err_exit $M 3284887Schinx='-(-[-)-]-' 3294887Schin[[ ${x/*%(()[])*/\1} == '-(-[-)-]-' ]] || err_exit $M 3304887Schinx='-(-[-]-)-' 3314887Schin[[ ${x/*%([]())*/\1} == '[-]' ]] || err_exit $M 3324887Schinx='-[-(-)-]-' 3334887Schin[[ ${x/*%([]())*/\1} == '[-(-)-]' ]] || err_exit $M 3344887Schinx='-(-[-)-]-' 3354887Schin[[ ${x/*%([]())*/\1} == '-(-[-)-]-' ]] || err_exit $M 3364887Schin 3374887Schinx='-((-))-' 3384887Schin[[ ${x/*%(())*/\1} == '(-)' ]] || err_exit $M 3394887Schinx='-((-))-' 3404887Schin[[ ${x/~(-g)*%(())*/\1} == '((-))-' ]] || err_exit $M 3414887Schinx='-((-))-' 3424887Schin[[ ${x/~(-g:*)*%(())*/\1} == '(-)' ]] || err_exit $M 3434887Schinx='-((-))-' 3444887Schin[[ ${x/~(+g)*%(())*/\1} == '(-)' ]] || err_exit $M 3454887Schinx='-((-))-' 3464887Schin[[ ${x/~(+g:*)*%(())*/\1} == '(-)' ]] || err_exit $M 3474887Schinx='-((-))-' 3484887Schin[[ ${x/*(?)*%(())*(?)*/:\1:\2:\3:} == ':-(:(-):)-:' ]] || err_exit $M 3494887Schinx='-((-))-' 3504887Schin[[ ${x/~(-g)*(?)*%(())*(?)*/:\1:\2:\3:} == '::((-))::-' ]] || err_exit $M 3514887Schinx='-((-))-' 3524887Schin[[ ${x/~(-g:*(?))*%(())*(?)*/:\1:\2:\3:} == '::(-):)-:' ]] || err_exit $M 3534887Schinx='-((-))-' 3544887Schin[[ ${x/~(+g)*(?)*%(())*(?)*/:\1:\2:\3:} == ':-(:(-):)-:' ]] || err_exit $M 3554887Schinx='-((-))-' 3564887Schin[[ ${x/~(+g:*(?))*%(())*(?)*/:\1:\2:\3:} == ':-(:(-):)-:' ]] || err_exit $M 3574887Schinx='call(a+b,x/(c/d),(0));' 3584887Schin[[ ${x/+([[:alnum:]])*([[:space:]])(*%(()))*/:\1:\2:\3:} == ':call::(a+b,x/(c/d),(0)):' ]] || err_exit $M 3594887Schin 3604887Schinx='-(-;-)-' 3614887Schin[[ ${x/*%(()D${D})*/\1} == '-(-;-)-' ]] || err_exit $M 3624887Schinx='-(-);-' 3634887Schin[[ ${x/*%(()D${D})*/\1} == '(-)' ]] || err_exit $M 3644887Schinx='-(-)\;-' 3654887Schin[[ ${x/*%(()D${D})*/\1} == '(-)' ]] || err_exit $M 3664887Schinx='-(-\;-)-' 3674887Schin[[ ${x/*%(()D${D}E${E})*/\1} == '(-\;-)' ]] || err_exit $M 3684887Schinx='-(-)\;-' 3694887Schin[[ ${x/*%(()D${D}E${E})*/\1} == '(-)' ]] || err_exit $M 3704887Schinx='-(-(-)\;-)-' 3714887Schin[[ ${x/*%(()D${D}E${E})*/\1} == '(-)' ]] || err_exit $M 3724887Schin 3734887Schinx='-(-")"-)-' 3744887Schin[[ ${x/*%(()Q${Q})*/\1} == '(-")"-)' ]] || err_exit $M 3754887Schinx='-(-\")"-)-' 3764887Schin[[ ${x/*%(()Q${Q})*/\1} == '(-\")"-)' ]] || err_exit $M 3774887Schinx='-(-\")\"-)-' 3784887Schin[[ ${x/*%(()Q${Q})*/\1} == '(-\")\"-)' ]] || err_exit $M 3794887Schinx=$'-(-\\\'")\\\'-)-' 3804887Schin[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'(-\\\'")\\\'-)' ]] || err_exit $M 3814887Schinx=$'-(-\\\'")"-)-' 3824887Schin[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M 3834887Schinx=$'-(-\\\'")"\'-)-' 3844887Schin[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M 3854887Schinx=$'-(-\\"\')\'\\"-)-' 3864887Schin[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 3874887Schinx=$'-(-\')\\\'\'-)-' 3884887Schin[[ ${x/*%(()Q${S}Q${Q})*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M 3894887Schinx=$'-(-\'")\'-)-' 3904887Schin[[ ${x/*%(()L${S}Q${Q})*/\1} == $'(-\'")\'-)' ]] || err_exit $M 3914887Schinx=$'-(-\\\'")"-)-' 3924887Schin[[ ${x/*%(()L${S}Q${Q})*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M 3934887Schinx=$'-(-\\\'")"\'-)-' 3944887Schin[[ ${x/*%(()L${S}Q${Q})*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M 3954887Schinx=$'-(-\\"\')\'\\"-)-' 3964887Schin[[ ${x/*%(()L${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 3974887Schinx=$'-(-\')\\\'\'-)-' 3984887Schin[[ ${x/*%(()L${S}Q${Q})*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M 3994887Schinx='-(-")"-)-' 4004887Schin[[ ${x/*%(()Q${Q})*/\1} == '(-")"-)' ]] || err_exit $M 4014887Schinx='-(-\")"-)-' 4024887Schin[[ ${x/*%(()Q${Q})*/\1} == '(-\")"-)' ]] || err_exit $M 4034887Schinx='-(-\")\"-)-' 4044887Schin[[ ${x/*%(()Q${Q})*/\1} == '(-\")\"-)' ]] || err_exit $M 4054887Schin 4064887Schinx='-(-\)-)-' 4074887Schin[[ ${x/*%(()E${E})*/\1} == '(-\)-)' ]] || err_exit $M 4084887Schinx='-(-\\)-)-' 4094887Schin[[ ${x/*%(()E${E})*/\1} == '(-\\)' ]] || err_exit $M 4104887Schinx='-(-\")"-)-' 4114887Schin[[ ${x/*%(()E${E}Q${Q})*/\1} == '(-\")' ]] || err_exit $M 4124887Schinx='-(-\")\"-)-' 4134887Schin[[ ${x/*%(()E${E}Q${Q})*/\1} == '(-\")' ]] || err_exit $M 4144887Schinx=$'-(-\'")"-)-' 4154887Schin[[ ${x/*%(()E${E}Q${S}Q${Q})*/\1} == $'-(-\'")"-)-' ]] || err_exit $M 4164887Schinx=$'-(-\\\'")"-)-' 4174887Schin[[ ${x/*%(()E${E}Q${S}Q${Q})*/\1} == $'(-\\\'")"-)' ]] || err_exit $M 4184887Schinx=$'-(-\\"\')\'\\"-)-' 4194887Schin[[ ${x/*%(()E${E}Q${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 4204887Schinx=$'-(-\\\'")"-)-' 4214887Schin[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'(-\\\'")"-)' ]] || err_exit $M 4224887Schinx=$'-(-\\"\')\'\\"-)-' 4234887Schin[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 4244887Schinx=$'-(-\\"\')\\\'\\"-)-' 4254887Schin[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'(-\\"\')\\\'\\"-)' ]] || err_exit $M 4264887Schinx=$'-(-\\"\')\\\'\\"\'-)-' 4274887Schin[[ ${x/*%(()E${E}L${S}Q${Q})*/\1} == $'-(-\\"\')\\\'\\"\'-)-' ]] || err_exit $M 4284887Schin 4294887Schinx='-(-;-)-' 4304887Schin[[ ${x/*%(()D\;)*/\1} == '-(-;-)-' ]] || err_exit $M 4314887Schinx='-(-);-' 4324887Schin[[ ${x/*%(()D\;)*/\1} == '(-)' ]] || err_exit $M 4334887Schinx='-(-)\;-' 4344887Schin[[ ${x/*%(()D\;)*/\1} == '(-)' ]] || err_exit $M 4354887Schinx='-(-\;-)-' 4364887Schin[[ ${x/*%(()D\;E\\)*/\1} == '(-\;-)' ]] || err_exit $M 4374887Schinx='-(-);-' 4384887Schin[[ ${x/*%(()D\;E\\)*/\1} == '(-)' ]] || err_exit $M 4394887Schinx='-(-)\;-' 4404887Schin[[ ${x/*%(()D\;E\\)*/\1} == '(-)' ]] || err_exit $M 4414887Schinx='-(-(-)\;-)-' 4424887Schin[[ ${x/*%(()D\;E\\)*/\1} == '(-)' ]] || err_exit $M 4434887Schin 4444887Schinx='-(-")"-)-' 4454887Schin[[ ${x/*%(()Q\")*/\1} == '(-")"-)' ]] || err_exit $M 4464887Schinx='-(-\")"-)-' 4474887Schin[[ ${x/*%(()Q\")*/\1} == '(-\")"-)' ]] || err_exit $M 4484887Schinx='-(-\")\"-)-' 4494887Schin[[ ${x/*%(()Q\")*/\1} == '(-\")\"-)' ]] || err_exit $M 4504887Schinx=$'-(-\\\'")\\\'-)-' 4514887Schin[[ ${x/*%(()Q\'Q\")*/\1} == $'(-\\\'")\\\'-)' ]] || err_exit $M 4524887Schinx=$'-(-\\\'")"-)-' 4534887Schin[[ ${x/*%(()Q\'Q\")*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M 4544887Schinx=$'-(-\\\'")"\'-)-' 4554887Schin[[ ${x/*%(()Q\'Q\")*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M 4564887Schinx=$'-(-\\"\')\'\\"-)-' 4574887Schin[[ ${x/*%(()Q\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 4584887Schinx=$'-(-\')\\\'\'-)-' 4594887Schin[[ ${x/*%(()Q\'Q\")*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M 4604887Schinx=$'-(-\'")\'-)-' 4614887Schin[[ ${x/*%(()L\'Q\")*/\1} == $'(-\'")\'-)' ]] || err_exit $M 4624887Schinx=$'-(-\\\'")"-)-' 4634887Schin[[ ${x/*%(()L\'Q\")*/\1} == $'-(-\\\'")"-)-' ]] || err_exit $M 4644887Schinx=$'-(-\\\'")"\'-)-' 4654887Schin[[ ${x/*%(()L\'Q\")*/\1} == $'(-\\\'")"\'-)' ]] || err_exit $M 4664887Schinx=$'-(-\\"\')\'\\"-)-' 4674887Schin[[ ${x/*%(()L\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 4684887Schinx=$'-(-\')\\\'\'-)-' 4694887Schin[[ ${x/*%(()L\'Q\")*/\1} == $'-(-\')\\\'\'-)-' ]] || err_exit $M 4704887Schinx='-(-")"-)-' 4714887Schin[[ ${x/*%(()Q\")*/\1} == '(-")"-)' ]] || err_exit $M 4724887Schinx='-(-\")"-)-' 4734887Schin[[ ${x/*%(()Q\")*/\1} == '(-\")"-)' ]] || err_exit $M 4744887Schinx='-(-\")\"-)-' 4754887Schin[[ ${x/*%(()Q\")*/\1} == '(-\")\"-)' ]] || err_exit $M 4764887Schin 4774887Schinx='-(-\)-)-' 4784887Schin[[ ${x/*%(()E\\)*/\1} == '(-\)-)' ]] || err_exit $M 4794887Schinx='-(-\\)-)-' 4804887Schin[[ ${x/*%(()E\\)*/\1} == '(-\\)' ]] || err_exit $M 4814887Schinx='-(-\")"-)-' 4824887Schin[[ ${x/*%(()E\\Q\")*/\1} == '(-\")' ]] || err_exit $M 4834887Schinx='-(-\")\"-)-' 4844887Schin[[ ${x/*%(()E\\Q\")*/\1} == '(-\")' ]] || err_exit $M 4854887Schinx=$'-(-\'")"-)-' 4864887Schin[[ ${x/*%(()E\\Q\'Q\")*/\1} == $'-(-\'")"-)-' ]] || err_exit $M 4874887Schinx=$'-(-\\\'")"-)-' 4884887Schin[[ ${x/*%(()E\\Q\'Q\")*/\1} == $'(-\\\'")"-)' ]] || err_exit $M 4894887Schinx=$'-(-\\"\')\'\\"-)-' 4904887Schin[[ ${x/*%(()E\\Q\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 4914887Schinx=$'-(-\\\'")"-)-' 4924887Schin[[ ${x/*%(()E\\L\'Q\")*/\1} == $'(-\\\'")"-)' ]] || err_exit $M 4934887Schinx=$'-(-\\"\')\'\\"-)-' 4944887Schin[[ ${x/*%(()E\\L\'Q\")*/\1} == $'(-\\"\')\'\\"-)' ]] || err_exit $M 4954887Schinx=$'-(-\\"\')\\\'\\"-)-' 4964887Schin[[ ${x/*%(()E\\L\'Q\")*/\1} == $'(-\\"\')\\\'\\"-)' ]] || err_exit $M 4974887Schinx=$'-(-\\"\')\\\'\\"\'-)-' 4984887Schin[[ ${x/*%(()E\\L\'Q\")*/\1} == $'-(-\\"\')\\\'\\"\'-)-' ]] || err_exit $M 4994887Schin 5004887Schinpattern=00 5014887Schinvar=100 5024887Schin[[ $( print $(( ${var%%00} )) ) == 1 ]] || err_exit "arithmetic with embeddded patterns fails" 5034887Schin[[ $( print $(( ${var%%$pattern} )) ) == 1 ]] || err_exit "arithmetic with embeddded pattern variables fails" 50410898Sroland.mainz@nrubsig.orgif [[ ax == @(a)* ]] && [[ ${.sh.match[1]:0:${#.sh.match[1]}} != a ]] 5054887Schinthen err_exit '${.sh.match[1]:1:${#.sh.match[1]}} not expanding correctly' 5064887Schinfi 5074887Schin 5084887Schinstring='foo(d:\nt\box\something)bar' 5094887Schinexpected='d:\nt\box\something' 5104887Schin[[ ${string/*\(+([!\)])\)*/\1} == "$expected" ]] || err_exit "substring expansion failed '${string/*\(+([!\)])\)*/\1}' returned -- '$expected' expected" 5114887Schinif [[ $($SHELL -c $'export LC_ALL=en_US.UTF-8; print -r "\342\202\254\342\202\254\342\202\254\342\202\254w\342\202\254\342\202\254\342\202\254\342\202\254" | wc -m' 2>/dev/null) == 10 ]] 51210898Sroland.mainz@nrubsig.orgthen LC_ALL=en_US.UTF-8 $SHELL -c b1=$'"\342\202\254\342\202\254\342\202\254\342\202\254w\342\202\254\342\202\254\342\202\254\342\202\254"; [[ ${b1:4:1} == w ]]' || err_exit 'multibyte ${var:offset:len} not working correctly' 5134887Schinfi 51410898Sroland.mainz@nrubsig.org{ $SHELL -c 'unset x;[[ ${SHELL:$x} == $SHELL ]]';} 2> /dev/null || err_exit '${var:$x} fails when x is not set' 51510898Sroland.mainz@nrubsig.org{ $SHELL -c 'x=;[[ ${SHELL:$x} == $SHELL ]]';} 2> /dev/null || err_exit '${var:$x} fails when x is null' 5168462SApril.Chin@Sun.COM 5178462SApril.Chin@Sun.COM# subject mode pattern result # 5188462SApril.Chin@Sun.COMset -- \ 5198462SApril.Chin@Sun.COM 'a$z' 'E' '[$]|#' 'a($)z' \ 5208462SApril.Chin@Sun.COM 'a#z' 'E' '[$]|#' 'a(#)z' \ 5218462SApril.Chin@Sun.COM 'a$z' 'Elr' '[$]|#' 'a$z' \ 5228462SApril.Chin@Sun.COM 'a#z' 'Elr' '[$]|#' 'a#z' \ 5238462SApril.Chin@Sun.COM 'a$' 'E' '[$]|#' 'a($)' \ 5248462SApril.Chin@Sun.COM 'a#' 'E' '[$]|#' 'a(#)' \ 5258462SApril.Chin@Sun.COM 'a$' 'Elr' '[$]|#' 'a$' \ 5268462SApril.Chin@Sun.COM 'a#' 'Elr' '[$]|#' 'a#' \ 5278462SApril.Chin@Sun.COM '$z' 'E' '[$]|#' '($)z' \ 5288462SApril.Chin@Sun.COM '#z' 'E' '[$]|#' '(#)z' \ 5298462SApril.Chin@Sun.COM '$z' 'Elr' '[$]|#' '$z' \ 5308462SApril.Chin@Sun.COM '#z' 'Elr' '[$]|#' '#z' \ 5318462SApril.Chin@Sun.COM '$' 'E' '[$]|#' '($)' \ 5328462SApril.Chin@Sun.COM '#' 'E' '[$]|#' '(#)' \ 5338462SApril.Chin@Sun.COM '$' 'Elr' '[$]|#' '($)' \ 5348462SApril.Chin@Sun.COM '#' 'Elr' '[$]|#' '(#)' \ 5358462SApril.Chin@Sun.COM 'a$z' 'E' '\$|#' 'a$z()' \ 5368462SApril.Chin@Sun.COM 'a$z' 'E' '\\$|#' 'a$z' \ 5378462SApril.Chin@Sun.COM 'a$z' 'E' '\\\$|#' 'a($)z' \ 5388462SApril.Chin@Sun.COM 'a#z' 'E' '\\\$|#' 'a(#)z' \ 5398462SApril.Chin@Sun.COM 'a$z' 'Elr' '\\\$|#' 'a$z' \ 5408462SApril.Chin@Sun.COM 'a#z' 'Elr' '\\\$|#' 'a#z' \ 5418462SApril.Chin@Sun.COM 'a$' 'E' '\\\$|#' 'a($)' \ 5428462SApril.Chin@Sun.COM 'a#' 'E' '\\\$|#' 'a(#)' \ 5438462SApril.Chin@Sun.COM 'a$' 'Elr' '\\\$|#' 'a$' \ 5448462SApril.Chin@Sun.COM 'a#' 'Elr' '\\\$|#' 'a#' \ 5458462SApril.Chin@Sun.COM '$z' 'E' '\\\$|#' '($)z' \ 5468462SApril.Chin@Sun.COM '#z' 'E' '\\\$|#' '(#)z' \ 5478462SApril.Chin@Sun.COM '$z' 'Elr' '\\\$|#' '$z' \ 5488462SApril.Chin@Sun.COM '#z' 'Elr' '\\\$|#' '#z' \ 5498462SApril.Chin@Sun.COM '$' 'E' '\\\$|#' '($)' \ 5508462SApril.Chin@Sun.COM '#' 'E' '\\\$|#' '(#)' \ 5518462SApril.Chin@Sun.COM '$' 'Elr' '\\\$|#' '($)' \ 5528462SApril.Chin@Sun.COM '#' 'Elr' '\\\$|#' '(#)' \ 5538462SApril.Chin@Sun.COM# do not delete this line # 5548462SApril.Chin@Sun.COMunset i o 5558462SApril.Chin@Sun.COMwhile (( $# >= 4 )) 5568462SApril.Chin@Sun.COMdo i=$1 5578462SApril.Chin@Sun.COM eval o="\${i/~($2)$3/\\(\\0\\)}" 5588462SApril.Chin@Sun.COM if [[ "$o" != "$4" ]] 5598462SApril.Chin@Sun.COM then err_exit "i='$1'; \${i/~($2)$3/\\(\\0\\)} failed -- expected '$4', got '$o'" 5608462SApril.Chin@Sun.COM fi 5618462SApril.Chin@Sun.COM eval o="\${i/~($2)($3)/\\(\\1\\)}" 5628462SApril.Chin@Sun.COM if [[ "$o" != "$4" ]] 5638462SApril.Chin@Sun.COM then err_exit "i='$1'; \${i/~($2)($3)/\\(\\1\\)} failed -- expected '$4', got '$o'" 5648462SApril.Chin@Sun.COM fi 5658462SApril.Chin@Sun.COM shift 4 5668462SApril.Chin@Sun.COMdone 5678462SApril.Chin@Sun.COM 5684887Schinexit $((Errors)) 569