[NTLUG:Discuss] More shell scripting madness
. Daniel
xdesign at hotmail.com
Thu Jul 5 14:21:27 CDT 2007
Consider changing your name to "Answer Man" :)
That's really interesting. The .* thing doesn't fully make sense, nor does
all that \( \) stuff. I'm thinking that's part of some "requisite
knowledge/understanding" that I don't presently contain. But I expect I'll
be able to implement it so long as I ensure that the characters I use are
not improper or otherwise need escaping.
>. Daniel wrote:
>...
> > But while hacking around, I came up with a question I haven't yet
figured
> > out.
> >
> > How can I set up an expression that tests if one string is found within
> > another. Let's say, for example, A="ABCDEFGHIJK" and B="CDEF".
Obviously
> > $B can be found within $A. But how to set up an expression where the
> > result is true or false and can run a conditional off of the result?
> >
>
>if expr "$A" : ".*$B" >/dev/null; then
> echo found
>fi
>
>The matched expression is a RE (Regular Expression). You can use this
>to parse out matched areas:
>
>e.g.
>
>expr "$A" : ".*\($B\)"
>
>
>Globbing patterns are portable inside of switch statements...
>
>case "$A" in
>*$B*)
> echo found
>;;
>*)
> echo "not found"
>;;
>esac
>
>In case that's more what you were looking for. Just remember that "$B"
>can't contain unescaped pattern matching chars.
>
>_______________________________________________
>http://www.ntlug.org/mailman/listinfo/discuss
_________________________________________________________________
IE6の機能を強化した最新版ブラウザがMSNユーザー向けになって登場!
http://promotion.msn.co.jp/ie7/
More information about the Discuss
mailing list