1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1982-2012 AT&T Intellectual Property # 5# and is licensed under the # 6# Eclipse Public License, Version 1.0 # 7# by AT&T Intellectual Property # 8# # 9# A copy of the License is available at # 10# http://www.eclipse.org/org/documents/epl-v10.html # 11# (with md5 checksum b35adb5213ca9657e911e9befb180842) # 12# # 13# Information and Software Systems Research # 14# AT&T Research # 15# Florham Park NJ # 16# # 17# David Korn <dgk@research.att.com> # 18# # 19######################################################################## 20function err_exit 21{ 22 print -u2 -n "\t" 23 print -u2 -r ${Command}[$1]: "${@:2}" 24 let Errors+=1 25} 26alias err_exit='err_exit $LINENO' 27 28Command=${0##*/} 29integer Errors=0 30 31tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 32trap "cd /; rm -rf $tmp" EXIT 33 34# test shell builtin commands 35builtin getconf 36: ${foo=bar} || err_exit ": failed" 37[[ $foo == bar ]] || err_exit ": side effects failed" 38set -- - foobar 39[[ $# == 2 && $1 == - && $2 == foobar ]] || err_exit "set -- - foobar failed" 40set -- -x foobar 41[[ $# == 2 && $1 == -x && $2 == foobar ]] || err_exit "set -- -x foobar failed" 42getopts :x: foo || err_exit "getopts :x: returns false" 43[[ $foo == x && $OPTARG == foobar ]] || err_exit "getopts :x: failed" 44OPTIND=1 45getopts :r:s var -r 46if [[ $var != : || $OPTARG != r ]] 47then err_exit "'getopts :r:s var -r' not working" 48fi 49OPTIND=1 50getopts :d#u OPT -d 16177 51if [[ $OPT != d || $OPTARG != 16177 ]] 52then err_exit "'getopts :d#u OPT=d OPTARG=16177' failed -- OPT=$OPT OPTARG=$OPTARG" 53fi 54OPTIND=1 55while getopts 'ab' option -a -b 56do [[ $OPTIND == $((OPTIND)) ]] || err_exit "OPTIND optimization bug" 57done 58 59USAGE=$'[-][S:server?Operate on the specified \asubservice\a:]:[subservice:=pmserver] 60 { 61 [p:pmserver] 62 [r:repserver] 63 [11:notifyd] 64 }' 65set pmser p rep r notifyd -11 66while (( $# > 1 )) 67do OPTIND=1 68 getopts "$USAGE" OPT -S $1 69 [[ $OPT == S && $OPTARG == $2 ]] || err_exit "OPT=$OPT OPTARG=$OPTARG -- expected OPT=S OPTARG=$2" 70 shift 2 71done 72 73false ${foo=bar} && err_exit "false failed" 74read <<! 75hello world 76! 77[[ $REPLY == 'hello world' ]] || err_exit "read builtin failed" 78print x:y | IFS=: read a b 79if [[ $a != x ]] 80then err_exit "IFS=: read ... not working" 81fi 82read <<! 83hello \ 84world 85! 86[[ $REPLY == 'hello world' ]] || err_exit "read continuation failed" 87read -d x <<! 88hello worldxfoobar 89! 90[[ $REPLY == 'hello world' ]] || err_exit "read builtin failed" 91read <<\! 92hello \ 93 world \ 94 95! 96[[ $REPLY == 'hello world' ]] || err_exit "read continuation2 failed" 97print "one\ntwo" | { read line 98 print $line | /bin/cat > /dev/null 99 read line 100} 101read <<\! 102\ 103a\ 104\ 105\ 106b 107! 108if [[ $REPLY != ab ]] 109then err_exit "read multiple continuation failed" 110fi 111if [[ $line != two ]] 112then err_exit "read from pipeline failed" 113fi 114line=two 115read line < /dev/null 116if [[ $line != "" ]] 117then err_exit "read from /dev/null failed" 118fi 119if [[ $(print -R -) != - ]] 120then err_exit "print -R not working correctly" 121fi 122if [[ $(print -- -) != - ]] 123then err_exit "print -- not working correctly" 124fi 125print -f "hello%nbar\n" size > /dev/null 126if (( size != 5 )) 127then err_exit "%n format of printf not working" 128fi 129print -n -u2 2>&1- 130[[ -w /dev/fd/1 ]] || err_exit "2<&1- with built-ins has side effects" 131x=$0 132if [[ $(eval 'print $0') != $x ]] 133then err_exit '$0 not correct for eval' 134fi 135$SHELL -c 'read x <<< hello' 2> /dev/null || err_exit 'syntax <<< not recognized' 136($SHELL -c 'read x[1] <<< hello') 2> /dev/null || err_exit 'read x[1] not working' 137unset x 138readonly x 139set -- $(readonly) 140if [[ " $@ " != *" x "* ]] 141then err_exit 'unset readonly variables are not displayed' 142fi 143if [[ $( for i in foo bar 144 do print $i 145 continue 10 146 done 147 ) != $'foo\nbar' ]] 148then err_exit 'continue breaks out of loop' 149fi 150(continue bad 2>/dev/null && err_exit 'continue bad should return an error') 151(break bad 2>/dev/null && err_exit 'break bad should return an error') 152(continue 0 2>/dev/null && err_exit 'continue 0 should return an error') 153(break 0 2>/dev/null && err_exit 'break 0 should return an error') 154breakfun() { break;} 155continuefun() { continue;} 156for fun in break continue 157do if [[ $( for i in foo 158 do ${fun}fun 159 print $i 160 done 161 ) != foo ]] 162 then err_exit "$fun call in ${fun}fun breaks out of for loop" 163 fi 164done 165if [[ $(print -f "%b" "\a\n\v\b\r\f\E\03\\oo") != $'\a\n\v\b\r\f\E\03\\oo' ]] 166then err_exit 'print -f "%b" not working' 167fi 168if [[ $(print -f "%P" "[^x].*b\$") != '*[!x]*b' ]] 169then err_exit 'print -f "%P" not working' 170fi 171if [[ $(print -f "%(pattern)q" "[^x].*b\$") != '*[!x]*b' ]] 172then err_exit 'print -f "%(pattern)q" not working' 173fi 174if [[ $(abc: for i in foo bar;do print $i;break abc;done) != foo ]] 175then err_exit 'break labels not working' 176fi 177if [[ $(command -v if) != if ]] 178then err_exit 'command -v not working' 179fi 180read -r var <<\! 181 182! 183if [[ $var != "" ]] 184then err_exit "read -r of blank line not working" 185fi 186mkdir -p $tmp/a/b/c 2>/dev/null || err_exit "mkdir -p failed" 187$SHELL -c "cd $tmp/a/b; cd c" 2>/dev/null || err_exit "initial script relative cd fails" 188 189trap 'print TERM' TERM 190exp=$'trap -- \'print TERM\' TERM\ntrap -- \'cd /; rm -rf '$tmp$'\' EXIT' 191got=$(trap) 192[[ $got == $exp ]] || err_exit "\$(trap) failed -- expected \"$exp\", got \"$got\"" 193exp='print TERM' 194got=$(trap -p TERM) 195[[ $got == $exp ]] || err_exit "\$(trap -p TERM) failed -- expected \"$exp\", got \"$got\"" 196 197[[ $($SHELL -c 'trap "print ok" SIGTERM; kill -s SIGTERM $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized' 198[[ $($SHELL -c 'trap "print ok" sigterm; kill -s sigterm $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized' 199[[ $($SHELL -c '( trap "" TERM);kill $$;print bad' == bad) ]] 2> /dev/null && err_exit 'trap ignored in subshell causes it to be ignored by parent' 200${SHELL} -c 'kill -1 -$$' 2> /dev/null 201[[ $(kill -l $?) == HUP ]] || err_exit 'kill -1 -pid not working' 202${SHELL} -c 'kill -1 -$$' 2> /dev/null 203[[ $(kill -l $?) == HUP ]] || err_exit 'kill -n1 -pid not working' 204${SHELL} -c 'kill -s HUP -$$' 2> /dev/null 205[[ $(kill -l $?) == HUP ]] || err_exit 'kill -HUP -pid not working' 206n=123 207typeset -A base 208base[o]=8# 209base[x]=16# 210base[X]=16# 211for i in d i o u x X 212do if (( $(( ${base[$i]}$(printf "%$i" $n) )) != n )) 213 then err_exit "printf %$i not working" 214 fi 215done 216if [[ $( trap 'print done' EXIT) != done ]] 217then err_exit 'trap on EXIT not working' 218fi 219if [[ $( trap 'print done' EXIT; trap - EXIT) == done ]] 220then err_exit 'trap on EXIT not being cleared' 221fi 222if [[ $(LC_MESSAGES=C type test) != 'test is a shell builtin' ]] 223then err_exit 'whence -v test not a builtin' 224fi 225builtin -d test 226if [[ $(type test) == *builtin* ]] 227then err_exit 'whence -v test after builtin -d incorrect' 228fi 229typeset -Z3 percent=$(printf '%o\n' "'%'") 230forrmat=\\${percent}s 231if [[ $(printf "$forrmat") != %s ]] 232then err_exit "printf $forrmat not working" 233fi 234if (( $(printf 'x\0y' | wc -c) != 3 )) 235then err_exit 'printf \0 not working' 236fi 237if [[ $(printf "%bx%s\n" 'f\to\cbar') != $'f\to' ]] 238then err_exit 'printf %bx%s\n not working' 239fi 240alpha=abcdefghijklmnop 241if [[ $(printf "%10.*s\n" 5 $alpha) != ' abcde' ]] 242then err_exit 'printf %10.%s\n not working' 243fi 244float x2=.0000625 245if [[ $(printf "%10.5E\n" x2) != 6.25000E-05 ]] 246then err_exit 'printf "%10.5E" not normalizing correctly' 247fi 248x2=.000000001 249if [[ $(printf "%g\n" x2 2>/dev/null) != 1e-09 ]] 250then err_exit 'printf "%g" not working correctly' 251fi 252#FIXME#($SHELL read -s foobar <<\! 253#FIXME#testing 254#FIXME#! 255#FIXME#) 2> /dev/null || err_exit ksh read -s var fails 256if [[ $(printf +3 2>/dev/null) != +3 ]] 257then err_exit 'printf is not processing formats beginning with + correctly' 258fi 259if printf "%d %d\n" 123bad 78 >/dev/null 2>/dev/null 260then err_exit "printf not exiting non-zero with conversion errors" 261fi 262if [[ $(trap --version 2> /dev/null;print done) != done ]] 263then err_exit 'trap builtin terminating after --version' 264fi 265if [[ $(set --version 2> /dev/null;print done) != done ]] 266then err_exit 'set builtin terminating after --veresion' 267fi 268unset -f foobar 269function foobar 270{ 271 print 'hello world' 272} 273OPTIND=1 274if [[ $(getopts $'[+?X\ffoobar\fX]' v --man 2>&1) != *'Xhello world'X* ]] 275then err_exit '\f...\f not working in getopts usage strings' 276fi 277if [[ $(printf '%H\n' $'<>"& \'\tabc') != '<>"& '	abc' ]] 278then err_exit 'printf %H not working' 279fi 280if [[ $(printf '%(html)q\n' $'<>"& \'\tabc') != '<>"& '	abc' ]] 281then err_exit 'printf %(html)q not working' 282fi 283if [[ $( printf 'foo://ab_c%(url)q\n' $'<>"& \'\tabc') != 'foo://ab_c%3C%3E%22%26%20%27%09abc' ]] 284then err_exit 'printf %(url)q not working' 285fi 286if [[ $(printf '%R %R %R %R\n' 'a.b' '*.c' '^' '!(*.*)') != '^a\.b$ \.c$ ^\^$ ^(.*\..*)!$' ]] 287then err_exit 'printf %T not working' 288fi 289if [[ $(printf '%(ere)q %(ere)q %(ere)q %(ere)q\n' 'a.b' '*.c' '^' '!(*.*)') != '^a\.b$ \.c$ ^\^$ ^(.*\..*)!$' ]] 290then err_exit 'printf %(ere)q not working' 291fi 292if [[ $(printf '%..:c\n' abc) != a:b:c ]] 293then err_exit "printf '%..:c' not working" 294fi 295if [[ $(printf '%..*c\n' : abc) != a:b:c ]] 296then err_exit "printf '%..*c' not working" 297fi 298if [[ $(printf '%..:s\n' abc def ) != abc:def ]] 299then err_exit "printf '%..:s' not working" 300fi 301if [[ $(printf '%..*s\n' : abc def) != abc:def ]] 302then err_exit "printf '%..*s' not working" 303fi 304[[ $(printf '%q\n') == '' ]] || err_exit 'printf "%q" with missing arguments' 305# we won't get hit by the one second boundary twice, right? 306[[ $(printf '%T\n' now) == "$(date)" ]] || 307[[ $(printf '%T\n' now) == "$(date)" ]] || 308err_exit 'printf "%T" now' 309behead() 310{ 311 read line 312 left=$(cat) 313} 314print $'line1\nline2' | behead 315if [[ $left != line2 ]] 316then err_exit "read reading ahead on a pipe" 317fi 318read -n1 y <<! 319abc 320! 321exp=a 322if [[ $y != $exp ]] 323then err_exit "read -n1 failed -- expected '$exp', got '$y'" 324fi 325print -n $'{ read -r line;print $line;}\nhello' > $tmp/script 326chmod 755 $tmp/script 327if [[ $($SHELL < $tmp/script) != hello ]] 328then err_exit 'read of incomplete line not working correctly' 329fi 330set -f 331set -- * 332if [[ $1 != '*' ]] 333then err_exit 'set -f not working' 334fi 335unset pid1 pid2 336false & 337pid1=$! 338pid2=$( 339 wait $pid1 340 (( $? == 127 )) || err_exit "job known to subshell" 341 print $! 342) 343wait $pid1 344(( $? == 1 )) || err_exit "wait not saving exit value" 345wait $pid2 346(( $? == 127 )) || err_exit "subshell job known to parent" 347env= 348v=$(getconf LIBPATH) 349for v in ${v//,/ } 350do v=${v#*:} 351 v=${v%%:*} 352 eval [[ \$$v ]] && env="$env $v=\"\$$v\"" 353done 354if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]] 355then err_exit '"name=value exec -c ..." not working' 356fi 357$SHELL -c 'OPTIND=-1000000; getopts a opt -a' 2> /dev/null 358[[ $? == 1 ]] || err_exit 'getopts with negative OPTIND not working' 359getopts 'n#num' opt -n 3 360[[ $OPTARG == 3 ]] || err_exit 'getopts with numerical arguments failed' 361if [[ $($SHELL -c $'printf \'%2$s %1$s\n\' world hello') != 'hello world' ]] 362then err_exit 'printf %2$s %1$s not working' 363fi 364val=$(( 'C' )) 365set -- \ 366 "'C" $val 0 \ 367 "'C'" $val 0 \ 368 '"C' $val 0 \ 369 '"C"' $val 0 \ 370 "'CX" $val 1 \ 371 "'CX'" $val 1 \ 372 "'C'X" $val 1 \ 373 '"CX' $val 1 \ 374 '"CX"' $val 1 \ 375 '"C"X' $val 1 376while (( $# >= 3 )) 377do arg=$1 val=$2 code=$3 378 shift 3 379 for fmt in '%d' '%g' 380 do out=$(printf "$fmt" "$arg" 2>/dev/null) 381 err=$(printf "$fmt" "$arg" 2>&1 >/dev/null) 382 printf "$fmt" "$arg" >/dev/null 2>&1 383 ret=$? 384 [[ $out == $val ]] || err_exit "printf $fmt $arg failed -- expected '$val', got '$out'" 385 if (( $code )) 386 then [[ $err ]] || err_exit "printf $fmt $arg failed, error message expected" 387 else [[ $err ]] && err_exit "$err: printf $fmt $arg failed, error message not expected -- got '$err'" 388 fi 389 (( $ret == $code )) || err_exit "printf $fmt $arg failed -- expected exit code $code, got $ret" 390 done 391done 392((n=0)) 393((n++)); ARGC[$n]=1 ARGV[$n]="" 394((n++)); ARGC[$n]=2 ARGV[$n]="-a" 395((n++)); ARGC[$n]=4 ARGV[$n]="-a -v 2" 396((n++)); ARGC[$n]=4 ARGV[$n]="-a -v 2 x" 397((n++)); ARGC[$n]=4 ARGV[$n]="-a -v 2 x y" 398for ((i=1; i<=n; i++)) 399do set -- ${ARGV[$i]} 400 OPTIND=0 401 while getopts -a tst "av:" OPT 402 do : 403 done 404 if [[ $OPTIND != ${ARGC[$i]} ]] 405 then err_exit "\$OPTIND after getopts loop incorrect -- expected ${ARGC[$i]}, got $OPTIND" 406 fi 407done 408options=ab:c 409optarg=foo 410set -- -a -b $optarg -c bar 411while getopts $options opt 412do case $opt in 413 a|c) [[ $OPTARG ]] && err_exit "getopts $options \$OPTARG for flag $opt failed, expected \"\", got \"$OPTARG\"" ;; 414 b) [[ $OPTARG == $optarg ]] || err_exit "getopts $options \$OPTARG failed -- \"$optarg\" expected, got \"$OPTARG\"" ;; 415 *) err_exit "getopts $options failed -- got flag $opt" ;; 416 esac 417done 418 419[[ $($SHELL 2> /dev/null -c 'readonly foo; getopts a: foo -a blah; echo foo') == foo ]] || err_exit 'getopts with readonly variable causes script to abort' 420 421unset a 422{ read -N3 a; read -N1 b;} <<! 423abcdefg 424! 425exp=abc 426[[ $a == $exp ]] || err_exit "read -N3 here-document failed -- expected '$exp', got '$a'" 427exp=d 428[[ $b == $exp ]] || err_exit "read -N1 here-document failed -- expected '$exp', got '$b'" 429read -n3 a <<! 430abcdefg 431! 432exp=abc 433[[ $a == $exp ]] || err_exit "read -n3 here-document failed -- expected '$exp', got '$a'" 434#(print -n a;sleep 1; print -n bcde) | { read -N3 a; read -N1 b;} 435#[[ $a == $exp ]] || err_exit "read -N3 from pipe failed -- expected '$exp', got '$a'" 436#exp=d 437#[[ $b == $exp ]] || err_exit "read -N1 from pipe failed -- expected '$exp', got '$b'" 438#(print -n a;sleep 1; print -n bcde) | read -n3 a 439#exp=a 440#[[ $a == $exp ]] || err_exit "read -n3 from pipe failed -- expected '$exp', got '$a'" 441#rm -f $tmp/fifo 442#if mkfifo $tmp/fifo 2> /dev/null 443#then (print -n a; sleep 1;print -n bcde) > $tmp/fifo & 444# { 445# read -u5 -n3 -t2 a || err_exit 'read -n3 from fifo timedout' 446# read -u5 -n1 -t2 b || err_exit 'read -n1 from fifo timedout' 447# } 5< $tmp/fifo 448# exp=a 449# [[ $a == $exp ]] || err_exit "read -n3 from fifo failed -- expected '$exp', got '$a'" 450# rm -f $tmp/fifo 451# mkfifo $tmp/fifo 2> /dev/null 452# (print -n a; sleep 1;print -n bcde) > $tmp/fifo & 453# { 454# read -u5 -N3 -t2 a || err_exit 'read -N3 from fifo timed out' 455# read -u5 -N1 -t2 b || err_exit 'read -N1 from fifo timedout' 456# } 5< $tmp/fifo 457# exp=abc 458# [[ $a == $exp ]] || err_exit "read -N3 from fifo failed -- expected '$exp', got '$a'" 459# exp=d 460# [[ $b == $exp ]] || err_exit "read -N1 from fifo failed -- expected '$exp', got '$b'" 461#fi 462#rm -f $tmp/fifo 463 464function longline 465{ 466 integer i 467 for((i=0; i < $1; i++)) 468 do print argument$i 469 done 470} 471# test command -x option 472integer sum=0 n=10000 473if ! ${SHELL:-ksh} -c 'print $#' count $(longline $n) > /dev/null 2>&1 474then for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) 2> /dev/null) 475 do ((sum += $i)) 476 done 477 (( sum == n )) || err_exit "command -x processed only $sum arguments" 478 command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1 479 [[ $? != 1 ]] && err_exit 'incorrect exit status for command -x' 480fi 481# test command -x option with extra arguments 482integer sum=0 n=10000 483if ! ${SHELL:-ksh} -c 'print $#' count $(longline $n) > /dev/null 2>&1 484then for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) one two three) #2> /dev/null) 485 do ((sum += $i)) 486 done 487 (( sum > n )) || err_exit "command -x processed only $sum arguments" 488 (( (sum-n)%3==0 )) || err_exit "command -x processed only $sum arguments" 489 (( sum == n+3)) && err_exit "command -x processed only $sum arguments" 490 command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1 491 [[ $? != 1 ]] && err_exit 'incorrect exit status for command -x' 492fi 493# test for debug trap 494[[ $(typeset -i i=0 495 trap 'print $i' DEBUG 496 while (( i <2)) 497 do (( i++)) 498 done) == $'0\n0\n1\n1\n2' ]] || err_exit "DEBUG trap not working" 499getconf UNIVERSE - ucb 500[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe" 501typeset -F3 start_x=SECONDS total_t delay=0.02 502typeset reps=50 leeway=5 503sleep $(( 2 * leeway * reps * delay )) | 504for (( i=0 ; i < reps ; i++ )) 505do read -N1 -t $delay 506done 507(( total_t = SECONDS - start_x )) 508if (( total_t > leeway * reps * delay )) 509then err_exit "read -t in pipe taking $total_t secs - $(( reps * delay )) minimum - too long" 510elif (( total_t < reps * delay )) 511then err_exit "read -t in pipe taking $total_t secs - $(( reps * delay )) minimum - too fast" 512fi 513$SHELL -c 'sleep $(printf "%a" .95)' 2> /dev/null || err_exit "sleep doesn't except %a format constants" 514$SHELL -c 'test \( ! -e \)' 2> /dev/null ; [[ $? == 1 ]] || err_exit 'test \( ! -e \) not working' 515[[ $(ulimit) == "$(ulimit -fS)" ]] || err_exit 'ulimit is not the same as ulimit -fS' 516tmpfile=$tmp/file.2 517print $'\nprint -r -- "${.sh.file} ${LINENO} ${.sh.lineno}"' > $tmpfile 518[[ $( . "$tmpfile") == "$tmpfile 2 1" ]] || err_exit 'dot command not working' 519print -r -- "'xxx" > $tmpfile 520[[ $($SHELL -c ". $tmpfile"$'\n print ok' 2> /dev/null) == ok ]] || err_exit 'syntax error in dot command affects next command' 521 522float sec=$SECONDS del=4 523exec 3>&2 2>/dev/null 524$SHELL -c "( sleep 1; kill -ALRM \$\$ ) & sleep $del" 2> /dev/null 525exitval=$? 526(( sec = SECONDS - sec )) 527exec 2>&3- 528(( exitval )) && err_exit "sleep doesn't exit 0 with ALRM interupt" 529(( sec > (del - 1) )) || err_exit "ALRM signal causes sleep to terminate prematurely -- expected 3 sec, got $sec" 530typeset -r z=3 531y=5 532for i in 123 z %x a.b.c 533do ( unset $i) 2>/dev/null && err_exit "unset $i should fail" 534done 535a=() 536for i in y y y[8] t[abc] y.d a.b a 537do unset $i || print -u2 "err_exit unset $i should not fail" 538done 539[[ $($SHELL -c 'y=3; unset 123 y;print $?$y') == 1 ]] 2> /dev/null || err_exit 'y is not getting unset with unset 123 y' 540[[ $($SHELL -c 'trap foo TERM; (trap;(trap) )') == 'trap -- foo TERM' ]] || err_exit 'traps not getting reset when subshell is last process' 541 542n=$(printf "%b" 'a\0b\0c' | wc -c) 543(( n == 5 )) || err_exit '\0 not working with %b format with printf' 544 545t=$(ulimit -t) 546[[ $($SHELL -c 'ulimit -v 15000 2>/dev/null; ulimit -t') == "$t" ]] || err_exit 'ulimit -v changes ulimit -t' 547 548$SHELL 2> /dev/null -c 'cd ""' && err_exit 'cd "" not producing an error' 549[[ $($SHELL 2> /dev/null -c 'cd "";print hi') != hi ]] && err_exit 'cd "" should not terminate script' 550 551bincat=$(whence -p cat) 552builtin cat 553out=$tmp/seq.out 554seq 11 >$out 555cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || err_exit "builtin cat differs from $bincat" 556 557[[ $($SHELL -c '{ printf %R "["; print ok;}' 2> /dev/null) == ok ]] || err_exit $'\'printf %R "["\' causes shell to abort' 558 559v=$( $SHELL -c $' 560 trap \'print "usr1"\' USR1 561 trap exit USR2 562 sleep 1 && { 563 kill -USR1 $$ && sleep 1 564 kill -0 $$ 2>/dev/null && kill -USR2 $$ 565 } & 566 sleep 2 | read 567 echo done 568' ) 2> /dev/null 569[[ $v == $'usr1\ndone' ]] || err_exit 'read not terminating when receiving USR1 signal' 570 571mkdir $tmp/tmpdir1 572cd $tmp/tmpdir1 573pwd=$PWD 574cd ../tmpdir1 575[[ $PWD == "$pwd" ]] || err_exit 'cd ../tmpdir1 causes directory to change' 576cd "$pwd" 577mv $tmp/tmpdir1 $tmp/tmpdir2 578cd .. 2> /dev/null || err_exit 'cannot change directory to .. after current directory has been renamed' 579[[ $PWD == "$tmp" ]] || err_exit 'after "cd $tmp/tmpdir1; cd .." directory is not $tmp' 580 581cd "$tmp" 582mkdir $tmp/tmpdir2/foo 583pwd=$PWD 584cd $tmp/tmpdir2/foo 585mv $tmp/tmpdir2 $tmp/tmpdir1 586cd ../.. 2> /dev/null || err_exit 'cannot change directory to ../.. after current directory has been renamed' 587[[ $PWD == "$tmp" ]] || err_exit 'after "cd $tmp/tmpdir2; cd ../.." directory is not $tmp' 588cd "$tmp" 589rm -rf tmpdir1 590 591cd /etc 592cd .. 593[[ $(pwd) == / ]] || err_exit 'cd /etc;cd ..;pwd is not /' 594cd /etc 595cd ../.. 596[[ $(pwd) == / ]] || err_exit 'cd /etc;cd ../..;pwd is not /' 597cd /etc 598cd .././.. 599[[ $(pwd) == / ]] || err_exit 'cd /etc;cd .././..;pwd is not /' 600cd /usr/bin 601cd ../.. 602[[ $(pwd) == / ]] || err_exit 'cd /usr/bin;cd ../..;pwd is not /' 603cd /usr/bin 604cd .. 605[[ $(pwd) == /usr ]] || err_exit 'cd /usr/bin;cd ..;pwd is not /usr' 606cd "$tmp" 607if mkdir $tmp/t1 608then ( 609 cd $tmp/t1 610 > real_t1 611 ( 612 cd .. 613 mv t1 t2 614 mkdir t1 615 ) 616 [[ -f real_t1 ]] || err_exit 'real_t1 not found after parent directory renamed in subshell' 617 ) 618fi 619cd "$tmp" 620 621$SHELL +E -i <<- \! && err_exit 'interactive shell should not exit 0 after false' 622 false 623 exit 624! 625 626if kill -L > /dev/null 2>&1 627then [[ $(kill -l HUP) == "$(kill -L HUP)" ]] || err_exit 'kill -l and kill -L are not the same when given a signal name' 628 [[ $(kill -l 9) == "$(kill -L 9)" ]] || err_exit 'kill -l and kill -L are not the same when given a signal number' 629 [[ $(kill -L) == *'9) KILL'* ]] || err_exit 'kill -L output does not contain 9) KILL' 630fi 631 632unset ENV 633v=$($SHELL 2> /dev/null +o rc -ic $'getopts a:bc: opt --man\nprint $?') 634[[ $v == 2* ]] || err_exit 'getopts --man does not exit 2 for interactive shells' 635 636read baz <<< 'foo\\\\bar' 637[[ $baz == 'foo\\bar' ]] || err_exit 'read of foo\\\\bar not getting foo\\bar' 638 639: ~root 640[[ $(builtin) == *.sh.tilde* ]] && err_exit 'builtin contains .sh.tilde' 641 642exit $((Errors<125?Errors:125)) 643