[plug] strncmp in shell

James Devenish devenish at guild.uwa.edu.au
Mon Jan 19 15:31:33 WST 2004


Hi,

In message <20040119071236.GF891 at postoffice.wa.bom.gov.au>
on Mon, Jan 19, 2004 at 03:12:36PM +0800, Russell Steicke wrote:
> On Mon, Jan 19, 2004 at 02:52:52PM +0800, James Devenish wrote:
> ...
> > $ FOO=oneone
> > $ echo ${FOO/one/}
> > one
> 
> Yes, but it doesn't expand to the empty string, for which I was testing.

But I didn't think you were testing for the behaviour of strncmp (since
the 'variable' portion of the string is left of the first slash, not to
its right). For example, the following strings:

    one, on, onex, oneone

used with strncmp(...,"one",3) will produce:

    equal, not equal, equal, equal

Yet, checking for the empty string after ${FOO/one/} produces these
corresponding results:

    true, false, false, false

I suspect the ${...:0:3} = "one" or $... == one* syntaxes would work,
though.





More information about the plug mailing list