Bug 5612

Summary: --help returns an error code
Product: Busybox Reporter: Tim Marston <ra00103>
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Host: Target:
Build:

Description Tim Marston 2012-10-19 15:47:46 UTC
When running some (all?) busybox commands, via symlink or explicitly on the command line, the "--help" command line argument is supported.  However, it returns exit code 1, signaling an error.

For example,

  $ symlink -s /bin/busybox sort
  $ ./sort --help
  BusyBox v1.20.2 (Debian 1:1.20.0-7) multi-call binary.
  
  Usage: sort [-nrugMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts [,end[.offset][opts]] [-t CHAR] [FILE]...
  
  [...rest of output cut...]
  $ echo $?
  1

The --help command line argument isn't POSIX (as far as I know), it's a GNU coding standard, which states that the exit code should be that of a success [1].  Therefor, this is probably a bug.

Incidentally, when running busybox with no command and using --help, no error is returned.

  $ busybox --help
  $ echo $?
  0

[1] http://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp
Comment 1 Denys Vlasenko 2013-01-17 10:04:48 UTC
CMD --help is intended to be run by user, not by script.
Scripts typically have not enough AI to use the output :)

Do you really rely on CMD --help's exit code?
Comment 2 Tim Marston 2013-02-01 15:14:02 UTC
OK, that's a good point.

I was trying to determine, in a Makefile, whether stty accepts a '-F' argument
(GNU, busybox) or '-f' argument (BSD/OSX).  The test I had been doing was to
assume that if the command supported --help (i.e., GNU long options), it would
also support -F:

  stty --help > /dev/null 2>&1 && echo -F || echo -f

But this doesn't work for busybox.  So I now using a test that defaults to -F
unless I can detect an explicit and specific error message from --help:

  stty --help 2>&1 | grep -q 'illegal option' && echo -f || echo -F

I realise these are both horrible and entirely unsupported ways of determining
command line arguments, but I couldn't think of a nice way that would be
suitable for use in a Makefile.

With regard to the exit code of --help, I still think that it would be nice if
busybox returned 0, if only for consistency.  But I accept your point entirely.
Comment 3 Denys Vlasenko 2013-02-28 11:35:15 UTC
Fixed in git:

commit efd0698f74caab0a0c8a51228b923ee142e8e278
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Thu Feb 28 12:34:18 2013 +0100

    make --help return exitcode 0. Closes 5612