(pattern|pattern|...), seem to work only within [[ ]] and not
for pathname expansion, case pattern matching, or substring expansion.
And sometimes [[ ]] gets it wrong (I think.) Is this
* known misbehavior?
* documented, and I didn't RTFM right?
* a bug on my platforms only? (11/16/88d, on RS6000 and RT)
Here's the script I used to test patterns with:
---------------------------
#!/bin/ksh
# called with a pattern as arg.
while read
do
echo ls: $(echo $REPLY)
for i in $(ls)
do
if [[ $i = $REPLY ]] then print if: $i matches "$REPLY"
else print if: $i does not match "$REPLY"
fi
case $i in
esac
case $i in
!(alpha)) print case: $i matches literal '!(alpha)';;
*) print case: $i does not match literal '!(alpha)';;
esac
case $i in
$REPLY) print case: $i matches "$REPLY";;
*) print case: $i does not match "$REPLY";;
esac
echo $i'#'$REPLY' -> ' ${i#$REPLY}
echo $i'##'$REPLY' -> ' ${i##$REPLY}
echo $i'%'$REPLY' -> ' ${i%$REPLY}
echo $i'%%'$REPLY' -> ' ${i%%$REPLY}
done
done
---------------------------------------
In a directory containing just two files 'alpha' and 'beta',
I execute the script above. Here's input, output, and comments.
(input) *
ls: alpha beta
if: alpha matches *
case: alpha matches literal !(alpha) // be reversed
case: alpha matches *
alpha#* -> lpha // bug: shortest * match is empty
alpha##* ->
alpha%* -> alpha // correct
alpha%%* ->
if: beta matches *
case: beta does not match literal !(alpha) // conditions?
case: beta matches *
beta#* -> eta // same bug
beta##* ->
beta%* -> beta
beta%%* ->
case: alpha matches literal !(alpha)
case: beta does not match literal !(alpha)
(input) *(beta)
if: alpha matches *(beta) // if is still wrong,
case: alpha matches literal !(alpha)
case: alpha does not match *(beta) // but correct nonmatch in case!
alpha#*(beta) -> alpha
alpha##*(beta) -> alpha
alpha%*(beta) -> alpha
alpha%%*(beta) -> alpha
if: beta matches *(beta) // if seems to like *(beta)
case: beta does not match literal !(alpha)
case: beta does not match *(beta) // and case doesn't.
beta#*(beta) -> beta
beta##*(beta) -> beta
beta%*(beta) -> beta
beta%%*(beta) -> beta
^D
So what happens on your platform?
--