[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#22045: expr substr returns with an error code 1 when the substring s
From: |
Assaf Gordon |
Subject: |
bug#22045: expr substr returns with an error code 1 when the substring starts with 0 |
Date: |
Sat, 28 Nov 2015 18:38:00 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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