Hi.
The newer shells, ksh and bash, have a lot of syntactical elements that are easily confused with one another.
The "Pattern Substitution Operators" syntax:
${variable_name}
can have a number of substitution operations with #, %, etc. They use the meta-characters, *, [], and ? -- page 123 ff, Learning the Korn Shell, 2nd Edition ("LTKS").
The "Patterns and Regular Expression" syntax uses:
*(exp), ?(exp), !(exp) ...
which correspond to the usual syntax we find in grep, etc:
grep "e*" ...
These patterns could be used within double brackets, for example:
if [[ $var == *!(e)* ]]
but not with string operator syntax (as far as I know) -- page 113 ff, 144 ff.
The ksh I use (pdksh, even on Solaris) notes a bad substitution for what I think is the right thing, but bash does it correctly in my opinion. Here's an example:
#!/bin/bash -
#!/bin/ksh -
# @(#) s1 Demonstrate string operators.
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1)
var='String operators rule!'
echo
echo " Replace e with _:"
echo ${var//e/_}
echo
echo " Replace everything except e with _:"
echo ${var//[^e]/_}
exit 0
Producing:
% ./s1
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
Replace e with _:
String op_rators rul_!
Replace everything except e with _:
_________e__________e_
Perhaps someone will stop by with a better explanation or a better suggestion ... cheers, drl