On Fri, Dec 13, 2024 at 07:56:08AM +0300, Michael Tokarev via Postfix-users
wrote:
> And second, the usage of "expr" utility is wrong, as it does
> not work when the system release is 0.something. Consider:
>
> expr 0.foo : '\([0-9]*\)'
This is a counter-intuitive oddity of the expr(1) regexp (":" operator):
-- Fedora:
$ echo $(expr 0 : '\([0-9]*\)'; echo $?)
0 1
$ echo $(expr 1 : '\([1-9]*\)'; echo $?)
1 0
-- NetBSD:
$ echo $(expr 0 : '\([0-9]*\)'; echo $?)
0 1
$ echo $(expr 1 : '\([1-9]*\)'; echo $?)
1 0
The usual X-prefix approach can save the day:
$ for input in 0 00 01 10 11 foo
do
num=$(expr "X${input}" : '\(X[0-9][0-9]*\)')
printf "%s -> '%s' (%d)\n" "$input" "$num" "$?"
done
0 -> 'X0' (0)
00 -> 'X00' (0)
01 -> 'X01' (0)
10 -> 'X10' (0)
11 -> 'X11' (0)
foo -> '' (1)
--
Viktor.
_______________________________________________
Postfix-users mailing list -- [email protected]
To unsubscribe send an email to [email protected]