expr applet bug?
Luciano Miguel Ferreira Rocha
strange at nsk.no-ip.org
Fri Dec 8 12:13:23 PST 2006
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,
* 2 if EXPRESSION is syntactically invalid,
* and 3 if an error occurred.
I suggest:
# 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:
--
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/20061208/91beb077/attachment.pgp
More information about the busybox
mailing list