tag 22045 notabug
close 22045
stop

Hello,

On 11/28/2015 03:47 PM, Matthias Klose wrote:
found with coreutils-8.23, expr substr returns with an error code when the 
substring consists of only '0' characters, and the match is started at position 
1.


$ expr substr 00001234 1 4; echo $?
0000
1
$ expr substr 00001234 1 5; echo $?
00001
0

'expr' is unique in its exit-codes: exit codes of 0 or 1 *do not* indicate 
success/error, but whether the result evaluated to null or zero:

From POSIX:
http://pubs.opengroup.org/onlinepubs/009695399/utilities/expr.html#tag_04_50_14
"
The following exit values shall be returned:
 0   The expression evaluates to neither null nor zero.
 1   The expression evaluates to null or zero.
 2   Invalid expression.
2   An error occurred.
"

And so, the exit codes you see indeed match the last computer value.

regards,
 - assaf







Reply via email to