[plug] strncmp in shell

Cameron Patrick cameron at patrick.wattle.id.au
Mon Jan 19 13:51:37 WST 2004


Hi all,

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(); }
or Python's:
	if foo[0:6] == 'wurble': stuff()

I'm aware of the case.....esac statement but would prefer something less
verbose.

Cameron.




More information about the plug mailing list