Bug 8796 - grep exit code, should be >1 in errors
Summary: grep exit code, should be >1 in errors
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.24.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-15 22:02 UTC by Aurelio Jargas
Modified: 2016-03-28 20:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aurelio Jargas 2016-03-15 22:02:05 UTC
POSIX says grep exit code should be 2 (or greater) when an error occurs.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html

   * 0 One or more lines were selected.
   * 1 No lines were selected.
   * >1 An error occurred.

That's how GNU grep behaves:

    $ grep '\(' /etc/passwd; echo $?
    grep: Unmatched ( or \(
    2

But Busybox is currently returning 1, which is the exit code we rely to check if the pattern not matched:

    / # grep '\(' /etc/passwd; echo $?
    grep: bad regex '\(': Missing ')'
    1

Could you please make it return 2 in case of errors?
Comment 1 Denys Vlasenko 2016-03-28 20:13:21 UTC
Fixed in git, thanks!