expr applet bug?

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Mon Dec 11 16:00:40 UTC 2006


On Sat, 9 Dec 2006, Luciano Miguel Ferreira Rocha wrote:

> On Sat, Dec 09, 2006 at 06:38:04PM +0100, Cristian Ionescu-Idbohrn wrote:
> > > Exit status is:
> > >  * 0 if EXPRESSION is neither null nor 0,
> > >  * 1 if EXPRESSION is null or 0,
> >
> > So, the line above is what IMO is a bug. The exit status should
> > not be 1 when the EXPRESSION is a perfectly valid 0.
>
> But expr is commonly used for math code, and most people want a
> result of 0 to be special.

Nevertheless the MATCH option is there too.

> The expected behaviour is subject to the user's opinion and desire,
> but I wouldn't call the current behaviour a bug.

I'm inclined to agree with you. Still...

> > Thanks for the workaround, but it's bloat :(
>
> It's only a wrapper for the program.

Yes, but I'm running expr on a "slow" embeded system and I need to
save every cycle I can. More shell code == bad.

> All the work is done by expr. The shell code only checks the output
> and error code and sets the error code to 0 if the output is 0. It's
> the behaviour you want.

Yes. That's what I want and I somehow have to pay for it.

> > Wouldn't it be easier to fix the bug?
> You have the code, you can change your version. Don't be surprised
> if other people's code that use expr gets broken by your change. But
> I suppose there isn't much code using expr out there.

FWIW, I found a discrepancy between bb-expr and gnu-expr:

busybox: expr xyz0 : '[^0-9]\+\([0-9]\+\)'
	 res=0, err=1
busybox: expr xyz00 : '[^0-9]\+\([0-9]\+\)'
	 res=00, err=0				<---

gnu:	 expr xyz0 : '[^0-9]\+\([0-9]\+\)'
	 res=0, err=1
	 expr xyz00 : '[^0-9]\+\([0-9]\+\)'
	 res=00, err=1

As you can see, gnu-expr returns exit status 1 for both xyz0 and
xyz00, but bb-expr doesn't.


Cheers,
Cristian



More information about the busybox mailing list