export 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 ' ' recho a* X* expect ' ' recho \a* # see if null glob expansion works shopt -s nullglob expect ' ' recho a* X* shopt -u nullglob # see if the failglob option works mkdir tmp touch tmp/l1 tmp/l2 tmp/l3 builtin echo tmp/l[12] tmp/*4 tmp/*3 shopt -s failglob builtin echo tmp/l[12] tmp/*4 tmp/*3 rm -r tmp shopt -u failglob # see if the code that expands directories only works expect '' recho b*/ # Test quoted and unquoted globbing characters expect '<*>' recho \* expect '' recho 'a*' expect '' recho a\* expect ' <*q*>' recho c* a\* *q* expect '<**>' recho "*"* expect '<**>' recho \** expect '<\.\./*/>' recho "\.\./*/" expect '' recho 's/\..*//' # Pattern from Larry Wall's Configure that caused bash to blow up expect '' recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/" # Make sure character classes work properly expect ' ' recho [a-c]b* expect '
' recho [a-y]*[^c] expect ' ' recho a*[^c] touch a-b aXb expect ' ' recho a[X-]b touch .x .y expect '
' recho [^a-c]* # Make sure that filenames with embedded globbing characters are handled # properly mkdir a\*b > a\*b/ooo expect '' recho a\*b/* expect '' recho a\*?/* expect '' cmd='echo !7' case "$cmd" in *\\!*) echo match ;; *) echo no match ;; esac expect '' file='r.*' case $file in *.\*) echo not there ;; *) echo there ;; esac # examples from the Posix.2 spec (d11.2, p. 243) expect '' recho a[b]c expect '' recho a["b"]c expect '' recho a[\b]c expect '' recho a?c expect '' case abc in a"b"c) echo 'match 1' ;; *) echo 'BAD match 1' ;; esac expect '' case abc in a*c) echo 'match 2' ;; *) echo 'BAD match 2' ;; esac expect '' case abc in "a?c") echo 'bad 1' ;; *) echo 'ok 1' ;; esac expect '' case abc in a\*c) echo 'bad 2' ;; *) echo 'ok 2' ;; esac expect '' case abc in a\[b]c) echo 'bad 3' ;; *) echo 'ok 3' ;; esac expect '' case "$nosuchvar" in "") echo 'ok 4' ;; *) echo 'bad 4' ;; esac # This is very odd, but sh and ksh seem to agree expect '' case abc in a["\b"]c) echo 'ok 5' ;; *) echo 'bad 5' ;; esac mkdir man mkdir man/man1 touch man/man1/bash.1 expect '' recho */man*/bash.* expect '' recho $(echo */man*/bash.*) expect '' 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 case abcdecdhjk in a****c**?**??*****) echo ok 25;; esac case '-' in [-abc]) echo ok 26 ;; esac case '-' in [abc-]) echo ok 27 ;; esac case '\' in \\) echo ok 28 ;; esac case '\' in [\\]) echo ok 29 ;; esac case '\' in '\') echo ok 30 ;; esac case '[' in [[]) echo ok 31 ;; esac # a `[' without a closing `]' is just another character to match, in the # bash implementation case '[' in [) echo ok 32 ;; esac case '[abc' in [*) echo 'ok 33';; esac # a right bracket shall lose its special meaning and represent itself in # a bracket expression if it occurs first in the list. -- POSIX.2 2.8.3.2 case ']' in []]) echo ok 34 ;; esac case '-' in []-]) echo ok 35 ;; esac # a backslash should just escape the next character in this context case p in [a-\z]) echo ok 36 ;; esac # this was a bug in all versions up to bash-2.04-release case "/tmp" in [/\\]*) echo ok 37 ;; esac # none of these should output anything case abc in ??**********?****?) echo bad 1;; esac case abc in ??**********?****c) echo bad 2;; esac case abc in ?************c****?****) echo bad 3;; esac case abc in *c*?**) echo bad 4;; esac case abc in a*****c*?**) echo bad 5;; esac case abc in a********???*******) echo bad 6;; esac case 'a' in []) echo bad 7 ;; esac case '[' in [abc) echo bad 8;; esac # let's start testing the case-insensitive globbing code recho b* shopt -s nocaseglob recho b* recho [b]* shopt -u nocaseglob # make sure set -f works right set -f recho * set +f # test out the GLOBIGNORE code GLOBIGNORE='.*:*c:*e:?' recho * GLOBIGNORE='.*:*b:*d:?' recho * # see if GLOBIGNORE can substitute for `set -f' GLOBIGNORE='.*:*' recho * unset GLOBIGNORE expect '' recho */man*/bash.* # make sure null values for GLOBIGNORE have no effect GLOBIGNORE= expect '' recho */man*/bash.* # this is for the benefit of pure coverage, so it writes the pcv file # in the right place, and for gprof builtin cd $MYDIR rm -rf $TESTDIR exit 0