expr applet bug?

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Sat Dec 9 17:38:04 UTC 2006


Thanks for pointing me to the docs.

On Fri, 8 Dec 2006, Luciano Miguel Ferreira Rocha wrote:

> On Fri, Dec 08, 2006 at 08:47:34PM +0100, Cristian Ionescu-Idbohrn wrote:
> > Isn't that a bug too? Does bb need to imitate bugs too?
>
> It's the defined behaviour in the documentation:
>
> 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.

> I suggest:

Thanks for the workaround, but it's bloat :(

> # 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...
Wouldn't it be easier to fix the bug?


Cheers,
Cristian



More information about the busybox mailing list