getopt(3) in echo(1)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

getopt(3) in echo(1)

Jan Stary
echo.c says

        /* This utility may NOT do getopt(3) option parsing. */

Why is that, for echo(1) specifically?
Other binaries in /bin seem to use getopt(3) freely.

        Jan

Reply | Threaded
Open this post in threaded view
|

Re: getopt(3) in echo(1)

Paul de Weerd
On Fri, Sep 30, 2016 at 04:40:16PM +0200, Jan Stary wrote:
| echo.c says
|
| /* This utility may NOT do getopt(3) option parsing. */
|
| Why is that, for echo(1) specifically?
| Other binaries in /bin seem to use getopt(3) freely.

Because echo should echo all arguments, including those that would
otherwise be parsed by getopt(3), except for '-n'.

Paul 'WEiRD' de Weerd

--
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/                 

Reply | Threaded
Open this post in threaded view
|

Re: getopt(3) in echo(1)

Otto Moerbeek
On Fri, Sep 30, 2016 at 04:47:33PM +0200, Paul de Weerd wrote:

> On Fri, Sep 30, 2016 at 04:40:16PM +0200, Jan Stary wrote:
> | echo.c says
> |
> | /* This utility may NOT do getopt(3) option parsing. */
> |
> | Why is that, for echo(1) specifically?
> | Other binaries in /bin seem to use getopt(3) freely.
>
> Because echo should echo all arguments, including those that would
> otherwise be parsed by getopt(3), except for '-n'.

To be more specific: --

See also http://pubs.opengroup.org/onlinepubs/9699919799/

        -Otto

Reply | Threaded
Open this post in threaded view
|

Re: getopt(3) in echo(1)

Alexander Hall
On September 30, 2016 5:16:57 PM GMT+02:00, Otto Moerbeek <[hidden email]>
wrote:

>On Fri, Sep 30, 2016 at 04:47:33PM +0200, Paul de Weerd wrote:
>
>> On Fri, Sep 30, 2016 at 04:40:16PM +0200, Jan Stary wrote:
>> | echo.c says
>> |
>> | /* This utility may NOT do getopt(3) option parsing. */
>> |
>> | Why is that, for echo(1) specifically?
>> | Other binaries in /bin seem to use getopt(3) freely.
>>
>> Because echo should echo all arguments, including those that would
>> otherwise be parsed by getopt(3), except for '-n'.
>
>To be more specific: --
>
>See also http://pubs.opengroup.org/onlinepubs/9699919799/

Direct link to the pretty useless "definition", leaving lots of room for
various implementations, all fulfilling the specs.

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

/Alexander

>
> -Otto