Update of /cvsroot/mingw/msys/packages/bash/2.05b/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10360/2.05b/tests Added Files: README arith-for.right arith-for.tests arith.right arith.tests array-at-star array.right array.tests array2.right braces-tests braces.right builtins.right builtins.tests builtins1.sub builtins2.sub cond.right cond.tests cprint.right cprint.tests dollar-at-star dollar.right dstack.right dstack.tests dstack2.right dstack2.tests errors.right errors.tests exec.right exec1.sub exec2.sub exec3.sub exec4.sub exec5.sub exec6.sub execscript exp-tests exp.right extglob.right extglob.tests extglob2.right extglob2.tests func.right func.tests func1.sub func2.sub func3.sub getopts.right getopts.tests getopts1.sub getopts2.sub getopts3.sub getopts4.sub getopts5.sub getopts6.sub getopts7.sub glob-test glob.right glob1.sub heredoc.right heredoc.tests herestr.right herestr.tests histexp.right histexp.tests history.list history.right history.tests ifs.right ifs.tests input-line.sh input-line.sub input.right invert.right invert.tests jobs.right jobs.tests jobs1.sub jobs2.sub jobs3.sub more-exp.right more-exp.tests new-exp.right new-exp.tests new-exp1.sub new-exp2.sub new-exp3.sub nquote.right nquote.tests nquote1.right nquote1.tests nquote2.right nquote2.tests nquote3.right nquote3.tests posix2.right posix2.tests posixpat.right posixpat.tests prec.right precedence printf.right printf.tests quote.right quote.tests read.right read.tests read1.sub read2.sub read3.sub read4.sub redir.right redir.tests redir1.sub redir2.sub redir3.in1 redir3.in2 redir3.sub redir4.in1 redir4.sub redir5.sub rhs-exp.right rhs-exp.tests rsh.right rsh.tests run-all run-arith run-arith-for run-array run-array2 run-braces run-builtins run-cond run-cprint run-dirstack run-dollars run-errors run-execscript run-exp-tests run-extglob run-extglob2 run-func run-getopts run-glob-test run-heredoc run-herestr run-histexpand run-history run-ifs run-input-test run-invert run-jobs run-minimal run-more-exp run-new-exp run-nquote run-nquote1 run-nquote2 run-nquote3 run-posix2 run-posixpat run-precedence run-printf run-quote run-read run-redir run-rhs-exp run-rsh run-set-e run-shopt run-strip run-test run-tilde run-trap run-type run-varenv set-e-test set-e.right shopt.right shopt.tests source1.sub source2.sub source3.sub source4.sub source5.sub strip.right strip.tests test.right test.tests tilde-tests tilde.right trap.right trap.tests trap1.sub trap2.sub trap2a.sub type.right type.tests varenv.right varenv.sh varenv1.sub varenv2.sub version version.mini Log Message: Pristine source --- NEW FILE: run-varenv --- ${THIS_SH} ./varenv.sh | grep -v '^expect' > /tmp/xx diff /tmp/xx varenv.right && rm -f /tmp/xx --- NEW FILE: run-input-test --- ${THIS_SH} < ./input-line.sh > /tmp/xx diff /tmp/xx input.right && rm -f /tmp/xx --- NEW FILE: precedence --- # @(#)precedence_test 1.0 91/07/24 Maarten Litmaath # test of relative precedences for `&&' and `||' operators echo "\`Say' echos its argument. Its return value is of no interest." case `echo -n` in '') Say () { echo -n "$*" ; } ;; *) Say () { echo "$*\c" ; } ;; esac echo "\`Truth' echos its argument and returns a TRUE result." Truth () { Say $1; return 0; } echo "\`False' echos its argument and returns a FALSE result." False () { Say $1; return 1; } echo "" cmd1='$open $test1 && $test2 $close || $test3' cmd2='$test1 || $open $test2 && $test3 $close' grouping_sh= grouping_C='( )' test3='Say 3' for i in 1 2 do eval proto=\$cmd$i for test1 in 'Truth 1' 'False 1' do for test2 in 'Truth 2' 'False 2' do for precedence in sh C do eval set x \$grouping_$precedence shift open=${1-' '} close=${2-' '} eval cmd=\""$proto"\" Say "$cmd output=" output=`eval "$cmd"` Say "$output" read correct || { echo 'Input fubar. Abort.' >&2; exit 1; } test "X$output" = "X$correct" || echo " correct=$correct" echo '' done echo '' done done done << EOF 12 12 123 123 13 13 13 13 13 1 13 1 123 123 12 12 EOF --- NEW FILE: run-builtins --- ${THIS_SH} ./builtins.tests > /tmp/xx 2>&1 diff /tmp/xx builtins.right && rm -f /tmp/xx --- NEW FILE: run-glob-test --- PATH=$PATH:`pwd` export PATH ${THIS_SH} ./glob-test | grep -v '^expect' > /tmp/xx diff /tmp/xx glob.right && rm -f /tmp/xx --- NEW FILE: run-cprint --- ${THIS_SH} ./cprint.tests > /tmp/xx 2>&1 diff /tmp/xx cprint.right && rm -f /tmp/xx --- NEW FILE: getopts5.sub --- #!/local/bin/bash #Time-stamp: <95/06/07 07:40:40 hr...@im...> getop () { local OPTIND local OPTERR=1 echo getop: OPTERR=$OPTERR while getopts ab arg "$@"; do case $arg in a) echo a here ;; b) echo b here ;; :|?|*) echo something else here ;; esac done echo getop: OPTIND=$OPTIND } OPTIND= OPTERR=0 echo OPTERR=$OPTERR while getopts ab arg; do case $arg in a) echo a here ;; b) echo b here ;; :|?|*) echo something else here ;; esac done echo OPTIND=$OPTIND getop "$@" -d -e echo OPTIND=$OPTIND echo OPTERR=$OPTERR --- NEW FILE: set-e.right --- 95 96 97 98 99 0 1 2 3 4 5 6 7 8 9 1 1 ok hi while succeeded until succeeded: 4 if succeeded AND list succeeded OR list succeeded ! succeeded eval succeeded ! eval succeeded -- 1 ! eval succeeded -- 2 --- NEW FILE: source5.sub --- LC_ALL=en_US unset LC_ALL unset LANG export LC_ALL=C export LANG=C set +o posix # attempting to source a non-existant file is not an error... . /tmp/source-notthere echo after bad source 1 set -o posix # ...unless you're in posix mode . /tmp/source-notthere echo after bad source 2 --- NEW FILE: run-new-exp --- echo "warning: two of these tests will fail if your OS does not support" >&2 echo "warning: named pipes or the /dev/fd filesystem. If the tests of the" >&2 echo "warning: process substitution mechanism fail, please do not consider" >&2 echo "warning: this a test failure" >&2 echo "warning: if you have exported variables beginning with the string _Q," >&2 echo "warning: diff output may be generated. If so, please do not consider" >&2 echo "warning: this a test failure" >&2 ${THIS_SH} ./new-exp.tests 2>&1 | grep -v '^expect' > /tmp/xx diff /tmp/xx new-exp.right && rm -f /tmp/xx --- NEW FILE: arith.tests --- set +o posix declare -i iv jv iv=$(( 3 + 5 * 32 )) echo $iv iv=iv+3 echo $iv iv=2 jv=iv let "jv *= 2" echo $jv jv=$(( $jv << 2 )) echo $jv let jv="$jv / 2" echo $jv jv="jv >> 2" echo $jv iv=$((iv+ $jv)) echo $iv echo $((iv -= jv)) echo $iv echo $(( iv == jv )) echo $(( iv != $jv )) echo $(( iv < jv )) echo $(( $iv > $jv )) echo $(( iv <= $jv )) echo $(( $iv >= jv )) echo $jv echo $(( ~$jv )) echo $(( ~1 )) echo $(( ! 0 )) echo $(( jv % 2 )) echo $(( $iv % 4 )) echo $(( iv <<= 16 )) echo $(( iv %= 33 )) echo $(( 33 & 55 )) echo $(( 33 | 17 )) echo $(( iv && $jv )) echo $(( $iv || jv )) echo $(( iv && 0 )) echo $(( iv & 0 )) echo $(( iv && 1 )) echo $(( iv & 1 )) echo $(( $jv || 0 )) echo $(( jv | 0 )) echo $(( jv | 1 )) echo $(( $jv || 1 )) let 'iv *= jv' echo $iv echo $jv let "jv += $iv" echo $jv echo $(( jv /= iv )) echo $(( jv <<= 8 )) echo $(( jv >>= 4 )) echo $(( iv |= 4 )) echo $(( iv &= 4 )) echo $(( iv += (jv + 9))) echo $(( (iv + 4) % 7 )) # unary plus, minus echo $(( +4 - 8 )) echo $(( -4 + 8 )) # conditional expressions echo $(( 4<5 ? 1 : 32)) echo $(( 4>5 ? 1 : 32)) echo $(( 4>(2+3) ? 1 : 32)) echo $(( 4<(2+3) ? 1 : 32)) echo $(( (2+2)<(2+3) ? 1 : 32)) echo $(( (2+2)>(2+3) ? 1 : 32)) # check that the unevaluated part of the ternary operator does not do # evaluation or assignment x=i+=2 y=j+=2 declare -i i=1 j=1 echo $((1 ? 20 : (x+=2))) echo $i,$x echo $((0 ? (y+=2) : 30)) echo $j,$y x=i+=2 y=j+=2 declare -i i=1 j=1 echo $((1 ? 20 : (x+=2))) echo $i,$x echo $((0 ? (y+=2) : 30)) echo $i,$y # check precedence of assignment vs. conditional operator # should be an error declare -i x=2 y=$((1 ? 20 : x+=2)) # check precedence of assignment vs. conditional operator declare -i x=2 echo $((0 ? x+=2 : 20)) # associativity of assignment-operator operator declare -i i=1 j=2 k=3 echo $((i += j += k)) echo $i,$j,$k # octal, hex echo $(( 0x100 | 007 )) echo $(( 0xff )) echo $(( 16#ff )) echo $(( 16#FF/2 )) echo $(( 8#44 )) echo $(( 8 ^ 32 )) # other bases echo $(( 16#a )) echo $(( 32#a )) echo $(( 56#a )) echo $(( 64#a )) echo $(( 16#A )) echo $(( 32#A )) echo $(( 56#A )) echo $(( 64#A )) echo $(( 64#@ )) echo $(( 64#_ )) # weird bases echo $(( 3425#56 )) # missing number after base echo $(( 2# )) # these should generate errors echo $(( 7 = 43 )) echo $(( 2#44 )) echo $(( 44 / 0 )) let 'jv += $iv' echo $(( jv += \$iv )) let 'rv = 7 + (43 * 6' # more errors declare -i i i=0#4 i=2#110#11 ((echo abc; echo def;); echo ghi) if (((4+4) + (4 + 7))); then echo ok fi (()) # make sure the null expression works OK a=(0 2 4 6) echo $(( a[1] + a[2] )) echo $(( (a[1] + a[2]) == a[3] )) (( (a[1] + a[2]) == a[3] )) ; echo $? # test pushing and popping the expression stack unset A A="4 + " echo $(( ( 4 + A ) + 4 )) A="3 + 5" echo $(( ( 4 + A ) + 4 )) # badly-formed conditional expressions echo $(( 4 ? : $A )) echo $(( 1 ? 20 )) echo $(( 4 ? 20 : )) # precedence and short-circuit evaluation B=9 echo $B echo $(( 0 && B=42 )) echo $B echo $(( 1 || B=88 )) echo $B echo $(( 0 && (B=42) )) echo $B echo $(( (${$} - $$) && (B=42) )) echo $B echo $(( 1 || (B=88) )) echo $B # until command with (( )) command x=7 echo $x until (( x == 4 )) do echo $x x=4 done echo $x # exponentiation echo $(( 2**15 - 1)) echo $(( 2**(16-1))) echo $(( 2**16*2 )) echo $(( 2**31-1)) echo $(( 2**0 )) # {pre,post}-{inc,dec}rement and associated errors x=4 echo $x echo $(( x++ )) echo $x echo $(( x-- )) echo $x echo $(( --x )) echo $x echo $(( ++x )) echo $x echo $(( ++7 )) echo $(( 7-- )) echo $(( --x=7 )) echo $(( ++x=7 )) echo $(( x++=7 )) echo $(( x--=7 )) echo $x echo $(( +7 )) echo $(( -7 )) echo $(( ++7 )) echo $(( --7 )) x=4 y=7 (( x=8 , y=12 )) echo $x $y # should be an error (( x=9 y=41 )) # These are errors unset b echo $((a b)) ((a b)) n=42 printf "%d\n" $n printf "%i\n" $n echo $(( 8#$(printf "%o\n" $n) )) printf "%u\n" $n echo $(( 16#$(printf "%x\n" $n) )) echo $(( 16#$(printf "%X\n" $n) )) --- NEW FILE: read2.sub --- a=4 read -t 2 a echo $? echo $a sleep 5 | read -t 1 a echo $? echo $a read -t -3 a echo $? echo $a # the above should all time out echo abcde | { read -t 2 a echo $a } --- NEW FILE: redir3.in1 --- ab cd --- NEW FILE: redir3.in2 --- root daemon --- NEW FILE: nquote3.right --- argv[1] = <uv^A^A> argv[1] = <uv^A^A> argv[1] = <uv^A> argv[1] = <uv^A> argv[1] = <^Ab> argv[1] = <^Ab> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <uv^Aw^Axy> argv[1] = <uv^A> argv[1] = <uv^A> argv[1] = <^Awx> argv[1] = <^Awx> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <uv^Aw^Axy> argv[1] = <uv^A> argv[1] = <uv^A> argv[1] = <^Awx> argv[1] = <^Awx> argv[1] = <uv^A> argv[1] = <uv^A> argv[1] = <^Awx> argv[1] = <^Awx> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <uv^Aw^Axy> argv[1] = <uv^Aw^Axy> argv[1] = <uv^A> argv[1] = <uv^A> argv[1] = <^Awx> argv[1] = <^Awx> argv[1] = <uv^A> argv[2] = <uv^Aw> argv[1] = <uv^A> argv[2] = <uv^Aw> argv[1] = <^Awx> argv[2] = <w^Axy> argv[1] = <^Awx> argv[2] = <w^Axy> argv[1] = <wx> argv[2] = <xy> argv[1] = <uv^A^Awx> argv[2] = <uv^Aw^Axy> argv[1] = <uv^A> argv[2] = <uv^Aw> argv[1] = <uv^A> argv[2] = <uv^Aw> argv[1] = <^Awx> argv[2] = <w^Axy> argv[1] = <^Awx> argv[2] = <w^Axy> argv[1] = <wx> argv[2] = <xy> argv[1] = <uv^A^Awx> argv[2] = <uv^Aw^Axy> --- NEW FILE: input-line.sub --- read line echo line read by $0 was \`$line\' --- NEW FILE: redir3.sub --- read line1 echo read line1 \"$line1\" exec 4<./redir3.in2 exec 5<&0 exec 0<&4 read line2 echo read line2 \"$line2\" exec 0<&5 read line3 echo read line3 \"$line3\" exec 0<&4 read line4 echo read line4 \"$line4\" exec 4<&- --- NEW FILE: read.right --- a. -a-b- -a-b- -a b- -a b- -a-b\- -a b\- -\-a b\- -\ a b\- -\-a b\- -\ a b\- argv[1] = <^A> argv[1] = <^A> argv[1] = <^?> argv[1] = <^?> argv[1] = <abcd> 1: x[A] y[B] z[] 1a: 2: x[A B] [A B ] [ A B ] ==aa== ==== ==== argv[1] = < foo> argv[1] = < foo> argv[1] = <foo> argv[1] = < foo> argv[1] = <foo> argv[1] = <foo> argv[1] = < foo> a = abcdefg a = xyz a = -xyz 123- a = abc 1 4 1 4 ./read2.sub: line 13: read: -3: invalid timeout specification 1 4 abcde ./read3.sub: line 4: read: -1: invalid number abc ab # while read -u 3 var do echo "$var" done 3<$0 --- NEW FILE: nquote1.tests --- a=$'a\001b' set $a b=$a c=$1 d="$1" e=$'uv\001\001wx' recho a $a ${#a} recho 1 $1 ${#1} recho b $b ${#b} recho c $c ${#c} recho d $d ${#d} recho a ${a} ${#a} recho 1 ${1} ${#1} recho b ${b} ${#b} recho c ${c} ${#c} recho d ${d} ${#d} recho a "$a" ${#a} recho 1 "$1" ${#1} recho b "$b" ${#b} recho c "$c" ${#c} recho d "$d" ${#d} recho a "${a}" ${#a} recho 1 "${1}" ${#1} recho b "${b}" ${#b} recho c "${c}" ${#c} recho d "${d}" ${#d} set $e recho e1 ${e:1:3} recho e2 "${e:1:3}" recho e3 ${1:1:3} recho e4 "${1:1:3}" arr[0]=$e arr[1]=$e recho a1 ${arr:0:4} recho a2 "${arr:0:4}" recho a3 ${arr[@]:0:2} recho a4 "${arr[@]:0:2}" set $e $e recho p1 ${@:1:2} recho p2 "${@:1:2}" recho p1 ${*:1:2} recho p2 "${*:1:2}" recho $e recho 'uvwx' f='uvwx' recho $f echo -en "\01" | cat -v echo huhu() { echo "$1"; }; huhu $(echo -en "\01") | cat -v huhu $(echo -en "\02") | cat -v f=$'uv\001w\001xy' set $f $f recho f1 ${f:1:3} recho f2 "${f:1:3}" arr[0]=$f arr[1]=$f recho a1 ${arr:0:4} recho a2 "${arr:0:4}" recho a3 ${arr[0]:0:4} recho a4 "${arr[0]:0:4}" recho e1 ${f:0:4} recho e2 "${f:0:4}" recho d1 ${1:2:2} recho d2 "${1:2:2}" recho @1 ${@:1:2} recho @2 "${@:1:2}" --- NEW FILE: run-exp-tests --- ${THIS_SH} ./exp-tests | grep -v '^expect' > /tmp/xx diff /tmp/xx exp.right && rm -f /tmp/xx --- NEW FILE: new-exp3.sub --- : # Set up some dummy variables beginning with _Q _QUANTITY= _QUOTA= _QUOTE= _QUILL= _QUEST= _QUART= recho ${!_Q*} IFS="-$IFS" recho ${!_Q*} recho "${!_Q*}" recho ${!_Y*} recho "${!_Q* }" IFS=$' \t\n' set a b c d e f g h i j k l m n o p recho ${!1*} recho ${!@*} --- NEW FILE: exp.right --- argv[1] = <^A> argv[1] = <^A> argv[1] = <^B> argv[1] = <^B> argv[1] = <^A> argv[1] = <^B> argv[1] = <abcdefgh> argv[1] = <abcdefgh> argv[1] = <abcdefgh> argv[1] = <abcdefgh> argv[1] = <abcd> argv[1] = <abcd> argv[1] = < > argv[1] = <--> argv[1] = <> argv[1] = <> argv[1] = <> argv[1] = <> argv[1] = <> argv[1] = <> argv[1] = <abc> argv[1] = <abc> argv[1] = <abc> argv[1] = <abc> argv[1] = <abcdef> argv[1] = <abcdef> argv[1] = <^A> argv[1] = <^B> argv[1] = <^A> argv[1] = <^B> argv[1] = <^A> argv[1] = <^B> argv[1] = <> argv[1] = <> argv[1] = <> argv[1] = <Hello world!> argv[1] = <`> argv[1] = <"> argv[1] = <\^A> argv[1] = <\$> argv[1] = <\\> argv[1] = <a> argv[2] = <b> argv[1] = <^A> argv[2] = <^B> argv[1] = <**> argv[1] = <\.\./*/> argv[1] = <^A^B^A^B> argv[1] = <^A^A> argv[1] = <^A^B> argv[1] = <^A^A^B> argv[1] = < abc> argv[2] = <def> argv[3] = <ghi> argv[4] = <jkl > argv[1] = < abc> argv[2] = <def> argv[3] = <ghi> argv[4] = <jkl > argv[1] = <--abc> argv[2] = <def> argv[3] = <ghi> argv[4] = <jkl--> argv[1] = <a b> argv[2] = <cd> argv[3] = <ef> argv[4] = <gh> argv[1] = <a b> argv[2] = <cd> argv[3] = <ef> argv[4] = <gh> argv[1] = <a b> argv[2] = <cd> argv[3] = <ef> argv[4] = <gh> argv[1] = < > argv[1] = < - > argv[1] = </^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/> argv[1] = <foo bar> argv[1] = <foo> argv[2] = <bar> argv[1] = <abc> argv[1] = <abc> argv[1] = <posix> argv[1] = <10> argv[1] = <file.o> argv[1] = <posix> argv[1] = </src/cmd> argv[1] = <three> argv[1] = <abcdef> argv[1] = <abcdef> argv[1] = <abcdef> argv[1] = <abcdef> argv[1] = <\$x> argv[1] = <$x> argv[1] = <\$x> argv[1] = <abc> argv[2] = <def> argv[3] = <ghi> argv[4] = <jkl> argv[1] = <abc def ghi jkl> argv[1] = <abc:def ghi:jkl> argv[1] = <abc> argv[2] = <def ghi> argv[3] = <jkl> argv[1] = <xxabc> argv[2] = <def ghi> argv[3] = <jklyy> argv[1] = <abc> argv[2] = <def ghi> argv[3] = <jklabc> argv[4] = <def ghi> argv[5] = <jkl> argv[1] = <abcdef> argv[1] = <bar> argv[2] = <> argv[3] = <xyz> argv[4] = <> argv[5] = <abc> argv[1] = <$foo> argv[1] = <10> argv[1] = <newline expected> argv[1] = <got it> argv[1] = <got it> argv[1] = <one> argv[2] = <three> argv[3] = <five> argv[1] = <5> argv[2] = <5> argv[1] = <3> argv[1] = <1> argv[1] = <1> argv[1] = <5> argv[1] = <5> argv[1] = <5> argv[1] = <5> argv[1] = <42> argv[1] = <26> argv[1] = <\> argv[1] = <~> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> --- NEW FILE: array-at-star --- # test the expansion of ${array[@]} and ${array[*]}, both quoted and # unquoted. the expansions should be exactly analogous to the # expansions of $@ and $* quoted and unquoted A=(a b) recho "${A[*]}" # If IFS is null, the parameters are joined without separators IFS='' recho "${A[*]}" # If IFS is unset, the parameters are separated by spaces unset IFS recho "${A[*]}" recho "${A[@]}" recho ${A[@]} IFS='/' A=(bob 'tom dick harry' joe) set ${A[*]} recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set ${A[*]} recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set ${A[@]} recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set ${A[@]} recho $# recho $1 recho $2 recho $3 # according to POSIX.2, unquoted $* should expand to multiple words if # $IFS is null, just like unquoted $@ IFS='' A=(bob 'tom dick harry' joe) set "${A[*]}" recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set ${A[*]} recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set ${A[@]} recho $# recho $1 recho $2 recho $3 # if IFS is unset, the individual positional parameters are split on # " \t\n" if $* or $@ are unquoted unset IFS A=(bob 'tom dick harry' joe) set ${A[*]} recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set ${A[@]} recho $# recho $1 recho $2 recho $3 # but not for "$@" or "$*" A=(bob 'tom dick harry' joe) set "${A[*]}" recho $# recho $1 recho $2 recho $3 A=(bob 'tom dick harry' joe) set "${A[@]}" recho $# recho $1 recho $2 recho $3 # these should both expand the value of A to multiple words A=(a b c d e) IFS="" recho ${A[@]} recho "${A[@]}" # this example is straight from the POSIX.2 rationale and adapted to arrays A=(foo bar bam) recho "${A[@]}" recho "${A[*]}" unset IFS recho "${A[@]}" recho ${A[@]} recho "${A[*]}" --- NEW FILE: builtins.tests --- # tests for miscellaneous builtins not tested elsewhere set +p set +o posix ulimit -c 0 2>/dev/null # alias/unalias tests unalias -a # this should return success, according to POSIX.2 alias echo alias: $? alias foo=bar unalias foo # this had better return success, according to POSIX.2 alias echo alias: $? # check that break breaks loops for i in a b c; do echo $i; break; echo bad-$i; done echo end-1 for i in a b c; do echo $i; break 1; echo bad-$i; done echo end-2 for i in a b c; do for j in x y z; do echo $i:$j break echo bad-$i done echo end-$i done echo end-3 # check that break breaks nested loops for i in a b c; do for j in x y z; do echo $i:$j break 2 echo bad-$i done echo end-$i done echo end # check that continue continues loops for i in a b c; do echo $i; continue; echo bad-$i ; done echo end-1 for i in a b c; do echo $i; continue 1; echo bad-$i; done echo end-2 for i in a b c; do for j in x y z; do echo $i:$j continue echo bad-$i-$j done echo end-$i done echo end-3 # check that continue breaks out of nested loops for i in a b c; do for j in x y z; do echo $i:$j continue 2 echo bad-$i-$j done echo end-$i done echo end # check that `eval' re-evaluates arguments, but `builtin' and `command' do not AVAR='$BVAR' BVAR=foo echo $AVAR builtin echo $AVAR command echo $AVAR eval echo \$AVAR eval echo $AVAR # test out eval with a temp environment AVAR=bar eval echo \$AVAR BVAR=xxx eval echo $AVAR unset -v AVAR BVAR # test umask mask=$(umask) umask 022 umask umask -S umask -S u=rwx,g=rwx,o=rx >/dev/null # 002 umask umask -S umask -p umask -p -S umask 0 umask -S umask ${mask} # restore original mask # builtin/command without arguments should do nothing. maybe someday they will builtin command # test enable enable -ps enable -aps ; enable -nps enable -n test case "$(type -t test)" in builtin) echo oops -- enable -n test failed ;; *) echo enable -n test worked ;; esac enable test case "$(type -t test)" in builtin) echo enable test worked ;; *) echo oops -- enable test failed ;; esac # test options to exec (exec -a specialname ${THIS_SH} -c 'echo $0' ) (exec -l -a specialname ${THIS_SH} -c 'echo $0' ) # test `clean' environment. if /bin/sh is bash, and the script version of # printenv is run, there will be variables in the environment that bash # sets on startup. Also test code that prefixes argv[0] with a dash. (export FOO=BAR ; exec -c -l printenv ) | grep FOO (FOO=BAR exec -c printenv ) | grep FOO (export FOO=BAR ; exec printenv ) | grep FOO (FOO=BAR exec printenv ) | grep FOO # ok, forget everything about hashed commands hash -r hash # this had better succeed, since command -p guarantees we will find the # standard utilties command -p hash rm # check out source/. # sourcing a zero-length-file had better not be an error rm -f /tmp/zero-length-file cp /dev/null /tmp/zero-length-file . /tmp/zero-length-file echo $? rm /tmp/zero-length-file AVAR=AVAR . ./source1.sub AVAR=foo . ./source1.sub . ./source2.sub echo $? set -- a b c . ./source3.sub # make sure source with arguments does not change the shell's positional # parameters, but that the sourced file sees the arguments as its # positional parameters echo "$@" . ./source3.sub x y z echo "$@" # but if the sourced script sets the positional parameters explicitly, they # should be reflected in the calling shell's positional parameters. this # also tests one of the shopt options that controls source using $PATH to # find the script echo "$@" shopt -u sourcepath . source4.sub echo "$@" # this is complicated when the sourced scripts gets its own positional # parameters from arguments to `.' set -- a b c echo "$@" . source4.sub x y z echo "$@" # test out cd and $CDPATH ${THIS_SH} ./builtins1.sub # test behavior of `.' when given a non-existant file argument ${THIS_SH} ./source5.sub # in posix mode, assignment statements preceding special builtins are # reflected in the shell environment. `.' and `eval' need special-case # code. set -o posix echo $AVAR AVAR=foo . ./source1.sub echo $AVAR AVAR=AVAR echo $AVAR AVAR=foo eval echo \$AVAR echo $AVAR AVAR=AVAR echo $AVAR AVAR=foo : echo $AVAR set +o posix # but assignment statements preceding `export' are always reflected in # the environment foo="" export foo declare -p foo unset foo # assignment statements preceding `declare' should be displayed correctly, # but not persist after the command FOO='$$' declare -p FOO declare -p FOO unset FOO # except for `declare -x', which should be equivalent to `export' FOO='$$' declare -x FOO declare -p FOO unset FOO # test out kill -l. bash versions prior to 2.01 did `kill -l num' wrong sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p') case "$(kill -l 1)" in ${sigone/SIG/}) echo ok;; *) echo oops -- kill -l failure;; esac # kill -l and trap -l should display exactly the same output sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p') if [ "$sigone" != "$sigonea" ]; then echo oops -- kill -l and trap -l differ fi # POSIX.2 says that exit statuses > 128 are mapped to signal names by # subtracting 128 so you can find out what signal killed a process case "$(kill -l $(( 128 + 1)) )" in ${sigone/SIG/}) echo ok;; *) echo oops -- kill -l 129 failure;; esac # out-of-range signal numbers should report the argument in the error # message, not 128 less than the argument kill -l 4096 # kill -l NAME should return the signal number kill -l ${sigone/SIG/} # test behavior of shopt xpg_echo ${THIS_SH} ./builtins2.sub # this must be last -- it is a fatal error exit status echo after bad exit --- NEW FILE: array2.right --- argv[1] = <a b> argv[1] = <ab> argv[1] = <a b> argv[1] = <a> argv[2] = <b> argv[1] = <a> argv[2] = <b> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <1> argv[1] = <bobtom dick harryjoe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <5> argv[1] = <bob> argv[1] = <tom> argv[1] = <dick> argv[1] = <5> argv[1] = <bob> argv[1] = <tom> argv[1] = <dick> argv[1] = <1> argv[1] = <bob> argv[2] = <tom> argv[3] = <dick> argv[4] = <harry> argv[5] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom> argv[2] = <dick> argv[3] = <harry> argv[1] = <joe> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> argv[1] = <foo> argv[2] = <bar> argv[3] = <bam> argv[1] = <foobarbam> argv[1] = <foo> argv[2] = <bar> argv[3] = <bam> argv[1] = <foo> argv[2] = <bar> argv[3] = <bam> argv[1] = <foo bar bam> --- NEW FILE: nquote2.right --- argv[1] = <a^Ab> argv[1] = <uv^A^Awx> argv[1] = <aAb> argv[1] = <aAb> argv[1] = <uvA^Awx> argv[1] = <uvA^Awx> argv[1] = <a^AB> argv[1] = <a^AB> argv[1] = <uv^A^AWx> argv[1] = <uv^A^AWx> argv[1] = <aAb> argv[1] = <aAb> argv[1] = <uvAAwx> argv[1] = <uvAAwx> argv[1] = <a^AB> argv[1] = <a^AB> argv[1] = <uv^A^AWx> argv[1] = <uv^A^AWx> argv[1] = <uvA^Awx> argv[2] = <uvA^Awx> argv[1] = <uvA^Awx> argv[2] = <uvA^Awx> argv[1] = <uv^A^AWx> argv[2] = <uv^A^AWx> argv[1] = <uv^A^AWx> argv[2] = <uv^A^AWx> argv[1] = <uvAAwx> argv[2] = <uvAAwx> argv[1] = <uvAAwx> argv[2] = <uvAAwx> argv[1] = <uv^A^AWx> argv[2] = <uv^A^AWx> argv[1] = <uv^A^AWx> argv[2] = <uv^A^AWx> argv[1] = <a^Ab> argv[1] = <uv^A^Awx> argv[1] = <aAb> argv[1] = <aAb> argv[1] = <uvA^Awx> argv[1] = <uvA^Awx> argv[1] = <a^AB> argv[1] = <a^AB> argv[1] = <uv^A^AWx> argv[1] = <uv^A^AWx> argv[1] = <aAb> argv[1] = <aAb> argv[1] = <uvAAwx> argv[1] = <uvAAwx> argv[1] = <a^AB> argv[1] = <a^AB> argv[1] = <uv^A^AWx> argv[1] = <uv^A^AWx> argv[1] = <aAb> argv[2] = <uvA^Awx> argv[1] = <aAb> argv[2] = <uvA^Awx> argv[1] = <a^AB> argv[2] = <uv^A^Awx> argv[1] = <a^AB> argv[2] = <uv^A^Awx> argv[1] = <a^Ab> argv[2] = <uv^A^AWx> argv[1] = <a^Ab> argv[2] = <uv^A^AWx> argv[1] = <aAb> argv[2] = <uvAAwx> argv[1] = <aAb> argv[2] = <uvAAwx> argv[1] = <a^AB> argv[2] = <uv^A^Awx> argv[1] = <a^AB> argv[2] = <uv^A^Awx> argv[1] = <a^Ab> argv[2] = <uv^A^AWx> argv[1] = <a^Ab> argv[2] = <uv^A^AWx> --- NEW FILE: ifs.right --- a:b:c a:b:c a:b:c a b c d e a:b:c:d:e a b c d e a:b:c:d:e a:b:c:d:e a b c d e a b c d e --- NEW FILE: input-line.sh --- echo before calling input-line.sub ${THIS_SH} ./input-line.sub this line for input-line.sub echo finished with input-line.sub --- NEW FILE: read4.sub --- while read -u 3 var do echo "$var" done 3<$0 --- NEW FILE: dollar-at-star --- # first, let's start with the basics recho "$@" recho "$*" recho $@ recho $* set a b recho "$*" # If IFS is null, the parameters are joined without separators IFS='' recho "$*" # If IFS is unset, the parameters are separated by spaces unset IFS recho "${*}" recho "$@" recho $@ IFS='/' set bob 'tom dick harry' joe set $* recho $# recho $1 recho $2 recho $3 set bob 'tom dick harry' joe set ${*} recho $# recho $1 recho $2 recho $3 set bob 'tom dick harry' joe set $@ recho $# recho $1 recho $2 recho $3 set bob 'tom dick harry' joe set ${@} recho $# recho $1 recho $2 recho $3 # according to POSIX.2, unquoted $* should expand to multiple words if # $IFS is null, just like unquoted $@ IFS='' set bob 'tom dick harry' joe set $* recho $# recho $1 recho $2 recho $3 set bob 'tom dick harry' joe set $@ recho $# recho $1 recho $2 recho $3 # if IFS is unset, the individual positional parameters are split on # " \t\n" if $* or $@ are unquoted unset IFS set bob 'tom dick harry' joe set $* recho $# recho $1 recho $2 recho $3 set bob 'tom dick harry' joe set $@ recho $# recho $1 recho $2 recho $3 # but not for "$@" or "$*" set bob 'tom dick harry' joe set "$*" recho $# recho $1 recho $2 recho $3 set bob 'tom dick harry' joe set "$@" recho $# recho $1 recho $2 recho $3 # POSIX.2 says these should both expand the positional parameters # to multiple words set a b c d e IFS="" recho $@ recho "$@" # this example is straight from the POSIX.2 rationale set foo bar bam recho "$@" recho "$*" unset IFS recho "$@" recho $@ recho "$*" IFS=: # special variables set -- 1 2 3 4 5 6 7 8 9 10 bar=${*} foo=$* echo foo = "$foo" echo bar = "$bar" foo1=$@ bar1=${@} echo foo1 = "$foo1" echo bar1 = "$bar1" foo2="$*" bar2="${*}" echo foo2 = "$foo2" echo bar2 = "$bar2" eval foo3='$*' bar3='${*}' echo foo3 = "$foo3" echo bar3 = "$bar3" case $* in *\:*) echo ok 1;; *) echo bad 1;; esac case $@ in *\:*) echo bad 2;; *) echo ok 2;; esac case "$*" in *\:*) echo ok 3;; *) echo bad 3;; esac case "$@" in *\:*) echo bad 4;; *) echo ok 4;; esac IFS=$' \t\n' bar=${*} foo=$* echo foo = "$foo" echo bar = "$bar" foo1=$@ bar1=${@} echo foo1 = "$foo1" echo bar1 = "$bar1" foo2="$*" bar2="${*}" echo foo2 = "$foo2" echo bar2 = "$bar2" eval foo3='$*' bar3='${*}' echo foo3 = "$foo3" echo bar3 = "$bar3" case $* in *\ *) echo ok 1;; *) echo bad 1;; esac case $@ in *\ *) echo ok 2;; *) echo bad 2;; esac case "$*" in *\ *) echo ok 3;; *) echo bad 3;; esac case "$@" in *\ *) echo ok 4;; *) echo bad 4;; esac exit 0 --- NEW FILE: getopts4.sub --- aflag= bflag= while getopts :ab: name "$@" do case $name in a) aflag=1 ;; b) bflag=1 bval=$OPTARG;; :) echo $0: error: option \`$OPTARG\' requires an argument echo Usage: $0 [-a] [-b value] args exit 2;; ?) echo $0: error: illegal option character \`$OPTARG\' echo Usage: $0 [-a] [-b value] args exit 2;; esac done if [ ! -z "$aflag" ] ; then echo -a specified ; fi if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi if [ "$OPTIND" -gt 1 ] then shift $(( $OPTIND - 1 )) fi echo remaining args: "$*" exit 0 --- NEW FILE: run-type --- ${THIS_SH} ./type.tests > /tmp/xx 2>&1 diff /tmp/xx type.right && rm -f /tmp/xx --- NEW FILE: set-e-test --- if : ; then set -e N=95 while :; do # expr returns 1 if expression is null or 0 set +e N_MOD_100=`expr $N % 100` set -e echo $N_MOD_100 N=`expr $N + 1` if [ $N -eq 110 ]; then break fi done set +e fi ( set -e false echo bad ) echo $? x=$( set -e false echo bad ) echo $? $x # command subst should not inherit -e set -e echo $(false; echo ok) if set +e then false fi echo hi set -e # a failing command in the compound list following a while, until, or # if should not cause the shell to exit while false; do echo hi done echo while succeeded x=1 until (( x == 4 )); do x=4 done echo until succeeded: $x if false; then echo oops fi echo if succeeded # failing commands that are part of an AND or OR list should not # cause the shell to exit false && echo AND list failed echo AND list succeeded false || echo OR list succeeded ! false echo ! succeeded # make sure eval preserves the state of the -e flag and `!' reserved word set -e if eval false; then echo oops fi echo eval succeeded ! eval false echo ! eval succeeded -- 1 ! eval '(exit 5)' echo ! eval succeeded -- 2 --- NEW FILE: dstack2.right --- expect ~1 ~1 /usr / /tmp /usr / /tmp /usr / these lines should be the same /tmp /tmp /tmp these lines should be the same /usr /usr /usr these lines should be the same / / / these lines should be the same /tmp /tmp /tmp these lines should be the same /usr /usr /usr 1 /usr these lines should be the same / / / --- NEW FILE: run-read --- ${THIS_SH} ./read.tests > /tmp/xx 2>&1 diff /tmp/xx read.right && rm -f /tmp/xx --- NEW FILE: run-getopts --- ${THIS_SH} ./getopts.tests > /tmp/xx 2>&1 diff /tmp/xx getopts.right && rm -f /tmp/xx --- NEW FILE: run-histexpand --- echo "warning: all of these tests will fail if history has not been compiled" >&2 echo "warning: into the shell" >&2 ${THIS_SH} ./histexp.tests > /tmp/xx 2>&1 diff /tmp/xx histexp.right && rm -f /tmp/xx --- NEW FILE: exec.right --- before exec1.sub: one two three calling exec1.sub aa bb cc dd ee after exec1.sub with args: 0 after exec1.sub without args: 0 ./execscript: line 20: notthere: command not found 127 notthere: notthere: No such file or directory 127 /bin/sh: /bin/sh: cannot execute binary file 126 ./execscript: line 32: /: is a directory 126 /: /: cannot execute binary file 126 ./execscript: line 39: .: /: is a directory 1 127 0 this is bashenv ./exec3.sub: line 3: /tmp/bash-notthere: No such file or directory ./exec3.sub: line 3: exec: /tmp/bash-notthere: cannot execute: No such file or directory 126 ./execscript: line 61: notthere: No such file or directory 127 ./execscript: line 64: notthere: No such file or directory 127 ./execscript: line 67: notthere: No such file or directory 127 this is sh this is sh unset ok 5 ./exec5.sub: line 4: exec: bash-notthere: not found 127 this is ohio-state 0 1 1 0 42 42 0 1 1 0 0 1 0 1 --- NEW FILE: heredoc.right --- there one - alpha two - beta three - gamma hi\ there$a stuff hi\ there EO\ F hi hi tab 1 tab 2 tab 3 abc def ghi jkl mno fff is a function fff () { ed /tmp/foo >/dev/null <<ENDOFINPUT /^name/d w q ENDOFINPUT aa=1 } fff is a function fff () { ed /tmp/foo >/dev/null <<ENDOFINPUT /^name/d w q ENDOFINPUT aa=1 } hi there --- NEW FILE: ifs.tests --- OIFS="$IFS" IFS=":$IFS" eval foo="a:b:c" IFS="$OIFS" echo $foo OIFS=$IFS IFS=":$IFS" foo=$(echo a:b:c) IFS=$OIFS for i in $foo do echo $i done OIFS=$IFS IFS=":$IFS" foo=`echo a:b:c` IFS=$OIFS for i in $foo do echo $i done DEFIFS=$' \t\n' # local copy of IFS that shadows global version function f { typeset IFS=: echo $1 } function ff { echo $1 } f a:b:c:d:e x=a:b:c:d:e echo $x IFS=: ff a:b:c:d:e echo $x # doesn't get word split IFS=$DEFIFS # variable assignment doesn't use new value for word splitting IFS=: echo $x # but does this time because of the eval IFS=: eval echo \$x # in posix mode, assignments preceding special builtins and functions are global set -o posix IFS=: export x echo $x IFS="$DEFIFS" --- NEW FILE: dollar.right --- argv[1] = <> argv[1] = <a b> argv[1] = <ab> argv[1] = <a b> argv[1] = <a> argv[2] = <b> argv[1] = <a> argv[2] = <b> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom dick harry> argv[1] = <joe> argv[1] = <5> argv[1] = <bob> argv[1] = <tom> argv[1] = <dick> argv[1] = <5> argv[1] = <bob> argv[1] = <tom> argv[1] = <dick> argv[1] = <1> argv[1] = <bob> argv[2] = <tom> argv[3] = <dick> argv[4] = <harry> argv[5] = <joe> argv[1] = <3> argv[1] = <bob> argv[1] = <tom> argv[2] = <dick> argv[3] = <harry> argv[1] = <joe> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> argv[1] = <foo> argv[2] = <bar> argv[3] = <bam> argv[1] = <foobarbam> argv[1] = <foo> argv[2] = <bar> argv[3] = <bam> argv[1] = <foo> argv[2] = <bar> argv[3] = <bam> argv[1] = <foo bar bam> foo = 1:2:3:4:5:6:7:8:9:10 bar = 1:2:3:4:5:6:7:8:9:10 foo1 = 1 2 3 4 5 6 7 8 9 10 bar1 = 1 2 3 4 5 6 7 8 9 10 foo2 = 1:2:3:4:5:6:7:8:9:10 bar2 = 1:2:3:4:5:6:7:8:9:10 foo3 = 1:2:3:4:5:6:7:8:9:10 bar3 = 1:2:3:4:5:6:7:8:9:10 ok 1 ok 2 ok 3 ok 4 foo = 1 2 3 4 5 6 7 8 9 10 bar = 1 2 3 4 5 6 7 8 9 10 foo1 = 1 2 3 4 5 6 7 8 9 10 bar1 = 1 2 3 4 5 6 7 8 9 10 foo2 = 1 2 3 4 5 6 7 8 9 10 bar2 = 1 2 3 4 5 6 7 8 9 10 foo3 = 1 2 3 4 5 6 7 8 9 10 bar3 = 1 2 3 4 5 6 7 8 9 10 ok 1 ok 2 ok 3 ok 4 --- NEW FILE: run-cond --- echo "warning: all of these tests will fail if the conditional command has not" >&2 echo "warning: been compiled into the shell" >&2 echo "warning: some of these tests will fail if extended pattern matching has not" >&2 echo "warning: been compiled into the shell" >&2 ${THIS_SH} ./cond.tests > /tmp/xx 2>&1 diff /tmp/xx cond.right && rm -f /tmp/xx --- NEW FILE: run-rhs-exp --- ${THIS_SH} ./rhs-exp.tests 2>&1 > /tmp/xx diff /tmp/xx rhs-exp.right && rm -f /tmp/xx --- NEW FILE: run-more-exp --- ${THIS_SH} ./more-exp.tests 2>&1 | grep -v '^expect' > /tmp/xx diff /tmp/xx more-exp.right && rm -f /tmp/xx --- NEW FILE: new-exp2.sub --- export LC_ALL=C export LANG=C # test out the new $(< filename) code # it should be exactly equivalent to $(cat filename) FILENAME=/tmp/bashtmp.x$$ trap 'rm -f $FILENAME' 0 cat >$FILENAME << EOF line 1 line 2 line 3 EOF LINES1=$(cat $FILENAME) LINES2=$(< $FILENAME) if [[ $LINES1 != $LINES2 ]]; then echo 'whoops: $(< filename) failed' fi LINES2=$(< /tmp/bashtmp.x*) if [[ $LINES1 != $LINES2 ]]; then echo 'whoops: $(< filename) with glob expansion failed' fi # but the glob expansion in the redirection should fail in posix mode set -o posix LINES2=$(< /tmp/bashtmp.x*) set +o posix # now see what happens when we try it with a non-existant file LINES3=$(< /tmp/redir-notthere) echo $? --- NEW FILE: redir.tests --- export LC_ALL=C export LANG=C # catch-all for remaining untested redirection stuff set +o posix echo abc > /tmp/redir-test cat /tmp/redir-test set -o noclobber #this should be an error echo def > /tmp/redir-test cat /tmp/redir-test # but this should succeed echo def > /tmp/redir-test-2 cat /tmp/redir-test-2 # and so should this echo def >| /tmp/redir-test cat /tmp/redir-test set +o noclobber rm /tmp/redir-test /tmp/redir-test-2 # this should be an error z="a b" cat < $z echo "Point 1" exec 3</etc/passwd exec 4>/tmp/bash-a exec 5>/tmp/bash-b echo "Point 2" echo to a 1>&4 echo to b 1>&5 cat /tmp/bash-a cat /tmp/bash-b exec 11</dev/null echo "Point 3" echo to a 1>&4 echo to b 1>&5 cat /tmp/bash-a cat /tmp/bash-b exec 11<&- echo "Point 4" exec 6<>/tmp/bash-c echo to c 1>&6 cat /tmp/bash-c echo "Point 5" rm -f /tmp/bash-a /tmp/bash-b /tmp/bash-c # # Test the effect of input buffering on the shell's input # ${THIS_SH} < redir1.sub # more open, close, duplicate file descriptors ${THIS_SH} ./redir3.sub < ./redir3.in1 # still more redirections ${THIS_SH} ./redir4.sub < redir4.in1 # various forms of null redirection testf() { if [ -f "$1" ]; then rm -f "$1" else echo oops -- $1 not found fi } > /tmp/null-redir-a testf /tmp/null-redir-a $EXIT > /tmp/null-redir-b testf /tmp/null-redir-b ( > /tmp/null-redir-c ) testf /tmp/null-redir-c $EXIT > /tmp/null-redir-d & wait testf /tmp/null-redir-d exit 3 | $EXIT > /tmp/null-redir-e echo $? -- ${PIPESTATUS[@]} testf /tmp/null-redir-e exit 4 | > /tmp/null-redir-f echo $? -- ${PIPESTATUS[@]} testf /tmp/null-redir-f > /tmp/null-redir-g & wait testf /tmp/null-redir-g exec >/tmp/null-redir-h & wait testf /tmp/null-redir-h # make sure async commands don't get /dev/null as stdin when an explicit # input redirection is supplied for x in 1 2 3; do { read line ; echo $line ; } & wait { read line ; echo $line ; } & wait done << EOF ab cd ef gh ij kl EOF # make sure async commands get /dev/null as stdin in the absence of any # input redirection /bin/cat & wait echo $? # make sure that loops work OK with here documents and are not run in # subshells while read line; do echo $line l2=$line done << EOF ab cd EOF echo $l2 # These should not echo anything -- bug in versions before 2.04 ( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1 ( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1 | cat # in posix mode, non-interactive shells are not allowed to perform # filename expansion on input redirections, even if they expand to # a single filename set -o posix cat < redir1.* # test ksh93 dup-and-close (move fd) redirections ${THIS_SH} ./redir5.sub --- NEW FILE: extglob2.tests --- # # More ksh-like extended globbing tests, cribbed from zsh-3.1.5 # shopt -s extglob failed=0 while read res str pat; do [[ $res = '#' ]] && continue [[ $str = ${pat} ]] ts=$? [[ $1 = -q ]] || echo "$ts: [[ $str = $pat ]]" if [[ ( $ts -gt 0 && $res = t) || ($ts -eq 0 && $res = f) ]]; then echo "Test failed: [[ $str = $pat ]]" (( failed += 1 )) fi done <<EOT t fofo *(f*(o)) t ffo *(f*(o)) t foooofo *(f*(o)) t foooofof *(f*(o)) t fooofoofofooo *(f*(o)) f foooofof *(f+(o)) f xfoooofof *(f*(o)) f foooofofx *(f*(o)) t ofxoofxo *(*(of*(o)x)o) f ofooofoofofooo *(f*(o)) t foooxfooxfoxfooox *(f*(o)x) f foooxfooxofoxfooox *(f*(o)x) t foooxfooxfxfooox *(f*(o)x) t ofxoofxo *(*(of*(o)x)o) t ofoooxoofxo *(*(of*(o)x)o) t ofoooxoofxoofoooxoofxo *(*(of*(o)x)o) t ofoooxoofxoofoooxoofxoo *(*(of*(o)x)o) f ofoooxoofxoofoooxoofxofo *(*(of*(o)x)o) t ofoooxoofxoofoooxoofxooofxofxo *(*(of*(o)x)o) t aac *(@(a))a@(c) t ac *(@(a))a@(c) f c *(@(a))a@(c) t aaac *(@(a))a@(c) f baaac *(@(a))a@(c) t abcd ?@(a|b)*@(c)d t abcd @(ab|a*@(b))*(c)d t acd @(ab|a*(b))*(c)d t abbcd @(ab|a*(b))*(c)d t effgz @(b+(c)d|e*(f)g?|?(h)i@(j|k)) t efgz @(b+(c)d|e*(f)g?|?(h)i@(j|k)) t egz @(b+(c)d|e*(f)g?|?(h)i@(j|k)) t egzefffgzbcdij *(b+(c)d|e*(f)g?|?(h)i@(j|k)) f egz @(b+(c)d|e+(f)g?|?(h)i@(j|k)) t ofoofo *(of+(o)) t oxfoxoxfox *(oxf+(ox)) f oxfoxfox *(oxf+(ox)) t ofoofo *(of+(o)|f) # The following is supposed to match only as fo+ofo+ofo t foofoofo @(foo|f|fo)*(f|of+(o)) t oofooofo *(of|oof+(o)) t fffooofoooooffoofffooofff *(*(f)*(o)) # The following tests backtracking in alternation matches t fofoofoofofoo *(fo|foo) # Exclusion t foo !(x) t foo !(x)* f foo !(foo) t foo !(foo)* t foobar !(foo) t foobar !(foo)* t moo.cow !(*.*).!(*.*) f mad.moo.cow !(*.*).!(*.*) f mucca.pazza mu!(*(c))?.pa!(*(z))? t fff !(f) t fff *(!(f)) t fff +(!(f)) t ooo !(f) t ooo *(!(f)) t ooo +(!(f)) t foo !(f) t foo *(!(f)) t foo +(!(f)) f f !(f) f f *(!(f)) f f +(!(f)) t foot @(!(z*)|*x) f zoot @(!(z*)|*x) t foox @(!(z*)|*x) t zoox @(!(z*)|*x) t foo *(!(foo)) f foob !(foo)b* t foobb !(foo)b* EOT echo "$failed tests failed." --- NEW FILE: exec5.sub --- # try exec'ing a command that cannot be found in $PATH shopt -s execfail exec bash-notthere # make sure we're still around echo $? # now we need to go away, but this should echo 'this is ohio-state' exec -a ohio-state ${THIS_SH} -c 'echo this is $0' --- NEW FILE: trap2.sub --- set +e trap 'echo ERRTRAP' ERR false false false echo after falses if ! false; then echo if negation ok fi ! false echo after negation while false; do echo while negation ok done echo after while ./trap2a.sub echo $(false ; echo command substitution) --- NEW FILE: func1.sub --- # # Test that redirections attached to shell functions are printed correctly. # This was a bug in all bash versions before bash-2.04. # f() { echo f-x echo f-y } >&2 type f export -f f ${THIS_SH} -c 'echo subshell; type f' f2() { echo f2-a f3() { echo f3-a echo f3-b } >&2 f3 } type f2 export -f f2 ${THIS_SH} -c 'echo subshell; type f2' f4() { echo f4-a f5() { echo f5-a echo f5-b } >&2 f5 } 2>&1 type f4 export -f f4 ${THIS_SH} -c 'echo subshell; type f4' testgrp() { echo testgrp-a { echo tg-x; echo tg-y; } >&2 echo testgrp-b } type testgrp export -f testgrp ${THIS_SH} -c 'echo subshell; type testgrp' --- NEW FILE: read1.sub --- a=7 echo 'abcdefg|xyz' | { read -d '|' a echo a = "${a-unset}" } echo xyz 123 | { read -d ' ' a echo a = "${a-unset}" } echo xyz 123 | { read -d $'\n' a echo a = -"${a-unset}"- } a=44 echo abcd | { read -d d a echo a = $a } exit 0 --- NEW FILE: glob1.sub --- # bash-2.01.1 failed this test FN=/tmp/bash-glob.$$ mkdir $FN cd $FN mkdir foo mkdir foobar touch foo/bar touch foobar/bar chmod 311 foo foobar echo f*/bar chmod 777 foo foobar cd / rm -rf $FN --- NEW FILE: trap1.sub --- # signals ignored at shell startup cannot be trapped or reset trap 'echo USR2' USR2 trap -p USR2 --- NEW FILE: redir1.sub --- # # Test the effect of input buffering on the shell's input # echo this is redir1.sub exec 0< redir2.sub echo BUG: after exec in redir1.sub --- NEW FILE: run-arith-for --- ${THIS_SH} ./arith-for.tests > /tmp/xx 2>&1 diff /tmp/xx arith-for.right && rm -f /tmp/xx --- NEW FILE: more-exp.right --- argv[1] = <aaa bbb ccc> argv[1] = <aaa bbb ccc> argv[1] = <baz:bar> argv[1] = <baz:bar> argv[1] = <aaa bbb ccc> argv[1] = <bar> argv[1] = <bar> argv[1] = <bar> argv[1] = <abcde> argv[1] = <abcde> argv[1] = <xyz> argv[1] = <a b> argv[2] = <c> argv[3] = <d> argv[4] = <e> argv[5] = <f> argv[1] = <a b> argv[1] = <a> argv[2] = <b> argv[1] = <a b> argv[2] = <c> argv[3] = <d> argv[4] = <e> argv[5] = <f> argv[1] = <a b> argv[2] = <c> argv[3] = <d> argv[4] = <e> argv[5] = <f> argv[1] = </usr/homes/chet> argv[1] = </usr/homes/chet> argv[1] = <~> argv[1] = <\~> argv[1] = <\ \~> argv[1] = <\ \ \~> argv[1] = </usr/homes/chet> argv[1] = </usr/homes/chet> argv[1] = </usr/homes/chet> argv[1] = <$HOME> argv[1] = <\ $HOME> argv[1] = <\ \ $HOME> argv[1] = <'bar'> argv[1] = <'bar'> argv[1] = <*@> argv[1] = <*@> argv[1] = <*@> argv[1] = <*@> argv[1] = <*@*> argv[1] = <*@*> argv[1] = <*@*> argv[1] = <*@*> argv[1] = <abcd> argv[1] = <efghijkl> argv[1] = <4> argv[2] = <2> argv[1] = <1> argv[1] = <bar> argv[1] = <2> argv[1] = <bar> argv[1] = <2> argv[1] = <4> argv[1] = <--\> argv[2] = <--> argv[1] = <--\^J--> argv[1] = <--+\> argv[2] = <+--> argv[1] = <--+\^J+--> argv[1] = <-+\> argv[2] = <+-\> argv[3] = <-> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <> argv[1] = <> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <xy> argv[1] = <> argv[1] = <> argv[1] = <x> argv[1] = <x> argv[1] = <> argv[1] = <x> argv[1] = <x> argv[1] = <x> argv[1] = <x> argv[1] = <^?> argv[1] = <^?> argv[1] = <x> argv[1] = <x> argv[1] = <> argv[2] = <abd> argv[3] = <x> argv[1] = <> argv[2] = <abd> argv[3] = <> argv[1] = <a,b,c,d,e,f> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> argv[6] = <f> ./more-exp.tests: line 269: abc=def: command not found argv[1] = <a b c d e> argv[1] = <a> argv[2] = <b> argv[3] = <c> argv[4] = <d> argv[5] = <e> argv[1] = <foo)> argv[1] = <a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\\a> argv[1] = <a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\\a> argv[1] = <a> argv[1] = <a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <$a> argv[1] = <\foo> argv[1] = <$a> argv[1] = <\foo> argv[1] = <\$a> argv[1] = <\\$a> argv[1] = <a> argv[1] = <a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <\a> argv[1] = <G> argv[2] = <{> argv[3] = <I> argv[4] = <K> argv[5] = <}> argv[1] = <hi> argv[2] = <K> argv[3] = <}> argv[1] = <a*> Number of args: 0 <${*-x}>: <x> <${@-x}>: <x> Number of args: 1 <${*-x}>: <> <${@-x}>: <> Number of args: 2 <${*-x}>: < > <${@-x}>: < > argv[1] = <5> argv[1] = <5> argv[1] = <5> argv[1] = <5> argv[1] = <5> argv[1] = <0> argv[1] = <0> argv[1] = <0> argv[1] = <0> argv[1] = <0> argv[1] = <0> argv[1] = <posparams> argv[1] = <posparams> argv[1] = <2> argv[1] = <0> argv[1] = <0> argv[1] = <1> argv[1] = <5> argv[1] = <5> argv[1] = <0> ./more-exp.tests: line 420: ${#:}: bad substitution ./more-exp.tests: line 422: ${#/}: bad substitution ./more-exp.tests: line 424: ${#%}: bad substitution ./more-exp.tests: line 426: ${#=}: bad substitution ./more-exp.tests: line 428: ${#+}: bad substitution ./more-exp.tests: line 430: ${#1xyz}: bad substitution ./more-exp.tests: line 433: #: %: syntax error: operand expected (error token is "%") argv[1] = <0> argv[1] = <a+b> argv[1] = <+> argv[1] = <+> argv[1] = <+> argv[1] = <G { I > argv[2] = <K> argv[3] = <}> argv[1] = <hi> argv[2] = <K> argv[3] = <}> argv[1] = <xxx> argv[2] = <yyy> 1 argv[1] = <> argv[1] = <> argv[1] = <> argv[1] = <:a:> argv[1] = <:b:> argv[1] = <> argv[1] = <> --- NEW FILE: invert.right --- 1 1 1 0 0 1 0 1 0 1 --- NEW FILE: rsh.tests --- # test restricted shell mode -- these should all be errors # # things not tested for: # adding builtins dynamically with enable -f # importing function definitions from environment set -r cd / PATH=$PATH:/usr/local/bin SHELL=/bin/sh /bin/sh -c 'echo /bin/sh executed' . ./source.sub3 rm -f /tmp/restricted echo abc > /tmp/restricted if [ -f /tmp/restricted ]; then echo oops 1 -- output fi echo abc >> /tmp/restricted if [ -f /tmp/restricted ]; then echo oops 2 -- append fi command -p date set +r set +o restricted exec /bin/date echo $0: after exec --- NEW FILE: func.right --- a returns 5 b returns 4 c returns 3 d returns 2 in e e returned 25 x is 25 ZZ abcde defghi ZZ 5 0 AVAR AVAR foo foo AVAR 5 5 f1 f1 () { ( return 5 ); status=$?; echo $status; return $status } before: try to assign to FUNCNAME outside: FUNCNAME = before: FUNCNAME = func FUNCNAME = func2 after: FUNCNAME = func outside2: FUNCNAME = function zf is a function zf () { echo this is zf } f is a function f () { echo f-x; echo f-y } 1>&2 subshell f is a function f () { echo f-x; echo f-y } 1>&2 f2 is a function f2 () { echo f2-a; function f3 () { echo f3-a; echo f3-b } 1>&2; f3 } subshell f2 is a function f2 () { echo f2-a; function f3 () { echo f3-a; echo f3-b } 1>&2; f3 } f4 is a function f4 () { echo f4-a; function f5 () { echo f5-a; echo f5-b } 1>&2; f5 } 2>&1 subshell f4 is a function f4 () { echo f4-a; function f5 () { echo f5-a; echo f5-b } 1>&2; f5 } 2>&1 testgrp is a function testgrp () { echo testgrp-a; { echo tg-x; echo tg-y } 1>&2; echo testgrp-b } subshell testgrp is a function testgrp () { echo testgrp-a; { echo tg-x; echo tg-y } 1>&2; echo testgrp-b } funca is a function funca () { ( echo func-a ) } funcb is a function funcb () { ( echo func-b ) } funcc is a function funcc () { ( echo func-c ) 2>&1 } func-a func-b func-c expect 5 10 5 10 expect 20 20 expect 5 20 5 20 expect 5 30 5 30 expect 2 40 2 40 expect 5 20 5 20 --- NEW FILE: histexp.tests --- LC_ALL=C LANG=C trap 'rm /tmp/newhistory' 0 file=bax histchars='!^#' # make sure history comment char is set correctly history -c HISTFILE=history.list HISTCONTROL=ignoreboth HISTIGNORE='&:#*:history*:fc*' # we will end up exercising the history stifling code as a result HISTSIZE=32 shopt -s cmdhist set -o history history -p '!!' # this should result in a failed history expansion error history -p '!!:z' history HISTFILE=/tmp/newhistory history -a history -w history -s "echo line 2 for history" history history -p '!e' history -p '!!' set -H !! !e history echo a b c d e !?ch? !-2 ^2^8 !2 # we're selecting /bin/sh -c ...; we want `sh' echo !-1:0:t # we're selecting /bin/sh -c ...; we want `/bin' echo !-2:0:h # we're selecting `echo a b c d e'; we want `e' echo !?d?:5 echo a b c d e echo !-1:2-$ echo !-2:2-4 echo !-2:3* echo !!:* echo !?a?:2- echo file.c echo !!:$:r echo !-2:$:e echo !-3:$:r:q echo $file.c echo !!:$:r echo !-2:^:e echo !-3:$:r:q echo a b c d e echo !!:1-$:x echo !-2:1-$:q echo foo.c foo.o foo.html foo.h !!:s/foo/bar/ !-2:gs/foo/bar/ !!:gs/bar/x&/ !-2:g& # make sure we can use any delimiter in the substitution, not just `/' !!:gs+bar+whix+ !!:p # wow echo !?.o?:%:r:q !!:0 !?.h?:%:q !!:-$ !:-$ history # make sure single quotes inhibit history expansion echo '!!' # make sure backslashes can quote the history expansion character echo \!\! # but other expansions on the line should still be processed echo '!!' !!:* history -c unset HISTFILE # make sure that the special bash cases are not history expanded case p in [!A-Z]) echo ok 1;; esac var1='ok 2' var2=var1 echo ${!var2} # Bash-2.01[.1] fails this test -- it attempts history expansion after the # history_expansion_char echo ok 3 # !1200 --- NEW FILE: arith.right --- 163 166 4 16 8 2 4 2 2 1 0 0 0 1 1 2 -3 -2 1 0 2 131072 29 33 49 1 1 0 0 1 1 1 2 3 1 58 2 60 1 256 16 62 4 29 5 -4 4 1 32 32 1 1 32 20 1,i+=2 30 1,j+=2 20 1,i+=2 30 1,j+=2 ./arith.tests: line 108: 1 ? 20 : x+=2: attempted assignment to non-variable (error token is "+=2") 20 6 6,5,3 263 255 255 127 36 40 10 10 10 10 10 10 36 36 62 63 ./arith.tests: line 143: 3425#56: illegal arithmetic base (error token is "3425#56") 0 ./arith.tests: line 149: 7 = 43 : attempted assignment to non-variable (error token is "= 43 ") ./arith.tests: line 150: 2#44: value too great for base (error token is "2#44") ./arith.tests: line 151: 44 / 0 : division by 0 (error token is " ") ./arith.tests: line 152: let: jv += $iv: syntax error: operand expected (error token is "$iv") ./arith.tests: line 153: jv += $iv : syntax error: operand expected (error token is "$iv ") ./arith.tests: line 154: let: rv = 7 + (43 * 6: missing `)' (error token is "6") ./arith.tests: line 158: 0#4: bad number (error token is "0#4") ./arith.tests: line 159: 2#110#11: bad number (error token is "2#110#11") abc def ghi ok 6 1 0 ./arith.tests: line 177: 4 + : syntax error: operand expected (error token is " ") 16 ./arith.tests: line 182: 4 ? : 3 + 5 : expression expected (error token is ": 3 + 5 ") ./arith.tests: line 183: 1 ? 20 : `:' expected for conditional expression (error token is " ") ./arith.tests: line 184: 4 ? 20 : : expression expected (error token is " ") 9 ./arith.tests: line 190: 0 && B=42 : attempted assignment to non-variable (error token is "=42 ") 9 ./arith.tests: line 193: 1 || B=88 : attempted assignment to non-variable (error token is "=88 ") 9 0 9 0 9 1 9 7 7 4 32767 32768 131072 2147483647 1 4 4 5 5 4 3 3 4 4 7 ./arith.tests: line 241: 7-- : syntax error: operand expected (error token is " ") ./arith.tests: line 243: --x=7 : attempted assignment to non-variable (error token is "=7 ") ./arith.tests: line 244: ++x=7 : attempted assignment to non-variable (error token is "=7 ") ./arith.tests: line 246: x++=7 : attempted assignment to non-variable (error token is "=7 ") ./arith.tests: line 247: x--=7 : attempted assignment to non-variable (error token is "=7 ") 4 7 -7 7 7 8 12 ./arith.tests: line 265: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ") ./arith.tests: line 269: a b: syntax error in expression (error token is "b") ./arith.tests: line 270: ((: a b: syntax error in expression (error token is "b") 42 42 42 42 42 42 --- NEW FILE: run-shopt --- ${THIS_SH} ./shopt.tests > /tmp/xx 2>&1 diff /tmp/xx shopt.right && rm -f /tmp/xx --- NEW FILE: input.right --- before calling input-line.sub line read by ./input-line.sub was `this line for input-line.sub' finished with input-line.sub --- NEW FILE: jobs3.sub --- #! /bin/bash NJOB=8 i=0 while [ $i -lt $NJOB ] do /bin/sh -c "sleep 4; exit 0" & rv=$? pid=$! eval bg_pid_$i=$pid # echo $$: Job $i: pid is $pid rv=$rv i=$((i + 1)) done i=0 while [ $i -lt $NJOB ] do eval wpid=\$bg_pid_$i echo Waiting for job $i #'('pid $wpid')' wait $wpid rv=$? echo job $i returns $rv i=$((i + 1)) done --- NEW FILE: redir5.sub --- # tests of ksh93-like dup-and-close redirection operators exec 9<$0 f() { exec 5<$0 exec 0<&5- while read line; do echo "$line" done } f typeset -f f # make sure it was closed read -u 5 foo echo after read exec 5<&0 exec <&- read abcde exec 0<&9- read line echo $line --- NEW FILE: run-set-e --- ${THIS_SH} ./set-e-test > /tmp/xx diff /tmp/xx set-e.right && rm -f /tmp/xx --- NEW FILE: braces-tests --- echo ff{c,b,a} echo f{d,e,f}g echo {l,n,m}xyz echo {abc\,def} echo {abc} echo \{a,b,c,d,e} echo {x,y,\{a,b,c}} echo {x\,y,\{abc\},trie} echo /usr/{ucb/{ex,edit},lib/{ex,how_ex}} echo XXXX\{`echo a b c | tr ' ' ','`\} eval echo XXXX\{`echo a b c | tr ' ' ','`\} echo {} echo { } echo } echo { echo abcd{efgh echo foo {1,2} bar echo `zecho foo {1,2} bar` echo $(zecho foo {1,2} bar) --- NEW FILE: source3.sub --- echo "$@" --- NEW FILE: glob-test --- LC_COLLATE=C # # test the shell globbing # expect() { echo expect "$@" } # First, a test that bash-2.01.1 fails ${THIS_SH} ./glob1.sub MYDIR=$PWD # save where we are TESTDIR=/tmp/glob-test mkdir $TESTDIR builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; } rm -rf * touch a b c d abc abd abe bb bcd ca cb dd de Beware mkdir bdir # see if `regular' globbing works right expect '<a> <abc> <abd> <abe> <X*>' recho a* X* expect '<a> <abc> <abd> <abe>' recho \a* # see if null glob expansion works shopt -s nullglob expect '<a> <abc> <abd> <abe>' recho a* X* shopt -u nullglob # see if the code that expands directories only works expect '<bdir/>' recho b*/ # Test quoted and unquoted globbing characters expect '<*>' recho \* expect '<a*>' recho 'a*' expect '<a*>' recho a\* expect '<c> <ca> <cb> <a*> <*q*>' recho c* a\* *q* expect '<**>' recho "*"* expect '<**>' recho \** expect '<\.\./*/>' recho "\.\./*/" expect '<s/\..*//>' recho 's/\..*//' # Pattern from Larry Wall's Configure that caused bash to blow up expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>' recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/" # Make sure character classes work properly expect '<abc> <abd> <abe> <bb> <cb>' recho [a-c]b* expect '<abd> <abe> <bb> <bcd> <bdir> <ca> <cb> <dd> <de>' recho [a-y]*[^c] expect '<abd> <abe>' recho a*[^c] touch a-b aXb expect '<a-b> <aXb>' recho a[X-]b touch .x .y expect '<Beware> <d> <dd> <de>' recho [^a-c]* # Make sure that filenames with embedded globbing characters are handled # properly mkdir a\*b > a\*b/ooo expect '<a*b/ooo>' recho a\*b/* expect '<a*b/ooo>' recho a\*?/* expect '<no match>' cmd='echo !7' case "$cmd" in *\\!*) echo match ;; *) echo no match ;; esac expect '<not there>' file='r.*' case $file in *.\*) echo not there ;; *) echo there ;; esac # examples from the Posix.2 spec (d11.2, p. 243) expect '<abc>' recho a[b]c expect '<abc>' recho a["b"]c expect '<abc>' recho a[\b]c expect '<abc>' recho a?c expect '<match 1>' case abc in a"b"c) echo 'match 1' ;; *) echo 'BAD match 1' ;; esac expect '<match 2>' case abc in a*c) echo 'match 2' ;; *) echo 'BAD match 2' ;; esac expect '<ok 1>' case abc in "a?c") echo 'bad 1' ;; *) echo 'ok 1' ;; esac expect '<ok 2>' case abc in a\*c) echo 'bad 2' ;; *) echo 'ok 2' ;; esac expect '<ok 3>' case abc in a\[b]c) echo 'bad 3' ;; *) echo 'ok 3' ;; esac expect '<ok 4>' case "$nosuchvar" in "") echo 'ok 4' ;; *) echo 'bad 4' ;; esac # This is very odd, but sh and ksh seem to agree expect '<ok 5>' case abc in a["\b"]c) echo 'ok 5' ;; *) echo 'bad 5' ;; esac mkdir man mkdir man/man1 touch man/man1/bash.1 expect '<man/man1/bash.1>' recho */man*/bash.* expect '<man/man1/bash.1>' recho $(echo */man*/bash.*) expect '<man/man1/bash.1>' recho "$(echo */man*/bash.*)" # tests with multiple `*'s case abc in a***c) echo ok 1;; esac case abc in a*****?c) echo ok 2;; esac case abc in ?*****??) echo ok 3;; esac case abc in *****??) echo ok 4;; esac case abc in *****??c) echo ok 5;; esac case abc in ?*****?c) echo ok 6;; esac case abc in ?***?****c) echo ok 7;; esac case abc in ?***?****?) echo ok 8;; esac case abc in ?***?****) echo ok 9;; esac case abc in *******c) echo ok 10;; esac case abc in *******?) echo ok 11;; esac case abcdecdhjk in a*cd**?**??k) echo ok 20;; esac case abcdecdhjk in a**?**cd**?**??k) echo ok 21;; esac case abcdecdhjk in a**?**cd**?**??k***) echo ok 22;; esac case abcdecdhjk in a**?**cd**?**??***k) echo ok 23;; esac case abcdecdhjk in a**?**cd**?**??***k**) echo ok 24;; esac ca... [truncated message content] |