[plug] strncmp in shell

James Devenish devenish at guild.uwa.edu.au
Mon Jan 19 14:23:29 WST 2004


In message <20040119061847.GC891 at postoffice.wa.bom.gov.au>
on Mon, Jan 19, 2004 at 02:18:47PM +0800, Russell Steicke wrote:
> > Does anyone here know what the equivalent of C's strncmp in shell
> > scripting is?  (Specifically I'm using bash, but the machines it'll be
> > running on will have zsh too and I'm willing to resort to that if
> > there's no easy way to do it with bash.)
> > 
> > What I want to do is say something like
> > 	if [ "$FOO[0-6]" = "wurble" ]; then (do stuff) fi
> > equivalent to C's
> > 	if (!strncmp(foo, "wurble", 6)) { stuff(); }

LOL. I guess I need to have some intake of liquids or solids today (for
some reason I read "strcasecmp" instead of "strncmp"). So...what is the
problem? I just tried out $FOO[0-6] in Bash and it didn't do much. So..
that is the "hypothetical" part of your post? I would imagine this would
work in zsh:

if [[ "$FOO" == "wurble*" ]]; then...fi





More information about the plug mailing list