bug-sed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54516: Sed help message error


From: Bob Proulx
Subject: bug#54516: Sed help message error
Date: Mon, 21 Mar 2022 21:53:32 -0600

Rolf Johns wrote:
> Here's a random bug I just found:
> sed|sed 's/sed/bob/g;'
> This should replace the word sed in the help but it doesn't since the help
> output is actually in the error pipe. With this version of the command
> it'll work however, which proves this:
> sed 2>&1|sed 's/sed/bob/g;'
>
> So, is this a feature or a bug considering "sed --help" outputs in the
> normal output pipe?

Running sed without any options is a usage error.  Since sed requires
at least a script as an argument parameter.  Since the sed script is
missing sed is emitting an error message to standard error and exiting
with an error status code.  (I'll note that awk does the same thing.)

    $ sed 2>/dev/null ; echo $?
    1

The sed --help is not an error.  In that case sed is being asked for
the help information.  And therefore it is being emitted to standard
output instead of standard error.  The exit code is success.

    $ sed --help >/dev/null ; echo $?
    0

All seems to be operating as desired.  Hope this explanation helps.

It's arguable that upon an error that *less* information should be
emitted to stderr.  Perhaps just the Usage line, a pointer to the
--help output, and nothing more.  Then the usage error would be less
likely to be confused with a help output message.  Such as for example
the way tar behaves.

    $ tar
    tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' 
options
    Try 'tar --help' or 'tar --usage' for more information.
    $ echo $?
    2

Bob





reply via email to

[Prev in Thread] Current Thread [Next in Thread]