Bug 8796

Summary: grep exit code, should be >1 in errors
Product: Busybox Reporter: Aurelio Jargas <aurelio>
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.24.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

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!