echo and getopt prohibition
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > echo and getopt prohibition




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    echo and getopt prohibition  
Bob Nelson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 12:17 AM

In the BSD (Open, Net and Free) ``echo.c'' source, the following comment
appears:

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

What prevents ``getopt'' from being used in the ``echo'' command?





[ Post a follow-up to this message ]



    Re: echo and getopt prohibition  
Roger Leigh


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 12:17 AM






[ Post a follow-up to this message ]



    Re: echo and getopt prohibition  
noogie.brown@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 12:17 AM

On Jul 22, 8:15 pm, Bob Nelson <bnel...@nelsonbe.com> wrote:
> In the BSD (Open, Net and Free) ``echo.c'' source, the following comment
> appears:
>
> /* This utility may NOT do getopt(3) option parsing. */
>
> What prevents ``getopt'' from being used in the ``echo'' command?

At a guess, maybe something to do with echo being an important tool
and it being available on a minimal install, perhaps where getopt
isn't available.






[ Post a follow-up to this message ]



    Re: echo and getopt prohibition  
Henry Townsend


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 06:19 AM

Bob Nelson wrote:
> In the BSD (Open, Net and Free) ``echo.c'' source, the following comment
> appears:
>
> /* This utility may NOT do getopt(3) option parsing. */
>
> What prevents ``getopt'' from being used in the ``echo'' command?

I would expect that it's because getopt swallows certain standard
sequences such as "--". In other words according to POSIX "echo -- foo"
must print "-- foo" but if getopt() was called it would print "foo".
This is purely speculative; I have not written a test.





[ Post a follow-up to this message ]



    Re: echo and getopt prohibition  
Geoff Clare


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 06:21 PM

Roger Leigh wrote:

> Bob Nelson <bnelson@nelsonbe.com> writes:
> 
>
> Nothing.  GNU echo (coreutils) as well as the bash echo builtin
> support options (-e, -n etc.).  There might be some ancient reason for
> the BSD behaviour, but it's certainly neither universal nor required.

It is required by POSIX:

"The echo utility shall not recognize the "--" argument in the
manner specified by Guideline 10 of the Base Definitions volume of
IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines;
"--" shall be recognized as a string operand.

Implementations shall not support any options.

[...]

If the first operand is -n, or if any of the operands contain a
backslash ('') character, the results are implementation-defined."

Note that it says "operand" when referring to -n, not "option".

POSIX requires "echo -e foo" to output "-e foo", and as far as I'm
aware GNU echo and the builtin echo in bash are the _only_ versions
of echo that do not conform to this POSIX requirement.

--
Geoff Clare <netnews@gclare.org.uk>





[ Post a follow-up to this message ]



    Re: echo and getopt prohibition  
Alan Curry


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 06:21 PM

In article <7pken4-208.ln1@leafnode-msgid.gclare.org.uk>,
Geoff Clare  <netnews@gclare.org.uk> wrote:
>
>POSIX requires "echo -e foo" to output "-e foo", and as far as I'm
>aware GNU echo and the builtin echo in bash are the _only_ versions
>of echo that do not conform to this POSIX requirement.

zsh builtin echo doesn't either, even in "emulate sh" mode with BSD_ECHO
turned on.

--
Alan Curry
pacman@world.std.com





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:29 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register