expr applet bug?

Luciano Miguel Ferreira Rocha strange at nsk.no-ip.org
Sat Dec 9 09:44:24 PST 2006


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.

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

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

> > # check text against regex (first argument)
> > check() {
> > 	regex="$1"
> > 	shift
> > 	result=$(./busybox expr "${*}" : "$regex")
> > 	[ -z "$result" ] && return 1
> > 	return 0
> > }
> >
> > $ check '[^0-9]\+\([0-9]\+\)' xyz0 ; echo $?: $result
> > 0: 0
> > $ check '[^0-9]\+\([0-9]\+\)' 0xyz0 ; echo $?: $result
> > 1:
> 
> All that (slow) shell code...

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.

> 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.

-- 
lfr
0/0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20061209/e5835b94/attachment.pgp 


More information about the busybox mailing list