[9fans] bug in echo? - Plan9

This is a discussion on [9fans] bug in echo? - Plan9 ; I was trying to echo the string '-n' and couldn't. This is because -n doesn't use ARGBEGIN. This command results in: echo -- -n -- -n I ended up doing echo a-n|sed s/a// Do I send the patch, do you ...

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 20 of 60

Thread: [9fans] bug in echo?

  1. [9fans] bug in echo?

    I was trying to echo the string '-n' and couldn't. This is because
    -n doesn't use ARGBEGIN.

    This command results in:

    echo -- -n
    -- -n

    I ended up doing

    echo a-n|sed s/a//

    Do I send the patch, do you consider this a bug?.

    --
    - curiosity sKilled the cat


  2. Re: [9fans] bug in echo?

    echo -n -n'
    '

    -rob


  3. Re: [9fans] bug in echo?

    The UNIX Programming Environment, p.78


  4. Re: [9fans] bug in echo?

    2008/3/26 Rob Pike :
    > echo -n -n'
    > '


    {echo -n -n; echo}

    But again, why not
    echo -- -n
    ?


    --
    - curiosity sKilled the cat


  5. Re: [9fans] bug in echo?

    > echo -- -n

    because we do gnot like that sort of stuff.



  6. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 1:40 PM, Anthony Martin wrote:
    > The UNIX Programming Environment, p.78
    >


    Plan 9 is not UNIX.
    The difference in code is:

    <
    < if(argc > 1)
    < if(strcmp(argv[1], "--") == 0){
    < argv++;
    < argc--;
    < }
    < else if(strcmp(argv[1], "-n") == 0)
    < nflag = 1;
    ---
    > if(argc > 1 && strcmp(argv[1], "-n") == 0)
    > nflag = 1;


    Which is not much.

    So, my question remains, why not?. Even in the UPE it says that
    the echo -n '
    '
    is ugly...
    --
    - curiosity sKilled the cat


  7. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 8:40 AM, Anthony Martin wrote:
    > The UNIX Programming Environment, p.78


    Followed by .

    --Joel


  8. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 1:52 PM, Sape Mullender
    wrote:
    > > echo -- -n

    >
    > because we do gnot like that sort of stuff.
    >
    >


    rm -- -r whynot
    rm: -r: '-r' file does not exist
    rm: whaynot: 'whaynot' file does not exist

    --
    - curiosity sKilled the cat


  9. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 9:13 AM, Gorka Guardiola wrote:
    > So, my question remains, why not?. Even in the UPE it says that
    > the echo -n '
    > '
    > is ugly...


    …At this point the Plan 9 realized history repeating itself, and
    although she did not want to offend either, she decided it was better
    to offend the impatient youth rather than subject all her suitors to
    yet another surfeit of notation.
    —From "Plan 9 and the Echo, with apologies to Doug McIlroy" by Russ
    Cox, linked to in my previous post.

  10. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 2:19 PM, Joel C. Salomon wrote:
    > At this point the Plan 9 realized history repeating itself, and
    > although she did not want to offend either, she decided it was better
    > to offend the impatient youth rather than subject all her suitors to
    > yet another surfeit of notation.
    > From "Plan 9 and the Echo, with apologies to Doug McIlroy" by Russ
    > Cox, linked to in my previous post.
    >


    Except, this is a different kind of problem.
    The file talks about

    echo ''

    which I understand should not be fixed because breaks other things and
    is a general case (as Russ points) of the question "what should we
    do when given an empty string / 0 size write etc." which is tricky
    and complicated.

    echo -- -n

    is a different kind of issue I think. I would just want to be told the
    reason(s) behind this.
    The fix doesn't break anything, makes echo consistent with the rest of
    programs and consists of two clear and simple lines of code.

    I wasn't trying to flame (originally, then I got carried away). I am
    just curious
    why this wasn't fixed.
    --
    - curiosity sKilled the cat


  11. Re: [9fans] bug in echo?

    > So, my question remains, why not?. Even in the UPE it says that
    > the echo -n '
    > '
    > is ugly...


    you could also echo ' -n' if the output can deal with a spurious
    space. or echo -n -n;echo

    this is a very odd case which can be worked around without adding --.
    the adding of which adds another odd case. what if you want to echo
    --? so adding -- special case code doesn't really solve any problems.

    an interesting question may be, why isn't "echo -n" a seperate program.

    in any event, i think this ship has sailed.

    - erik



  12. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 2:55 PM, erik quanstrom wrote:

    > --? so adding -- special case code doesn't really solve any problems.


    echo -- --?




    --
    - curiosity sKilled the cat


  13. Re: [9fans] bug in echo?

    > this is a very odd case

    odd but important. it's worth knowing that

    x=`{read}
    echo $x

    can transform more than just white space.

    personally, i'd vote for allowing -- just for
    the above case: echoing unknown text.
    the first argument to echo is not always a known constant.

    FWIW,

    echo '' $x

    will often be sufficient, if the output ignores leading white space.


  14. Re: [9fans] bug in echo?

    >> this is a very odd case
    >
    > odd but important. it's worth knowing that


    what's your reasoning that this is an important case?

    - erik



  15. Re: [9fans] bug in echo?

    Is there a valid reason to have echo process the arguments given?
    It's a simple mod:

    #include
    #include

    /* echo: echo args */
    void
    main(int argc, char *argv[])
    {
    int nl = 1;

    ARGBEGIN{
    'n':
    nl = 0;
    break;
    default:
    fprint(2, "usage: echo [-n] stuff\n");
    sysfatal("usage");
    }ARGEND;
    for(i = 1; i < argc - 1; i++)
    print("%s ", argv[i]);
    print("%s%s", argv[argc - 1], nl ? "\n" : "");
    exits(0);
    }

    However, Plan 9 has gone for years and people have not had this
    problem. (Then again, so did TUPE for Unix).

    Can we stick with

    echo -n '-n
    '

    as Rob (the coauthor of that book, mind you, so he knows EXACTLY what
    he is saying) said? It defies the need for handing a single argument.

    If we start supporting arguments, we can have other arguments:

    -e Use escape sequences.
    -E Use no escape sequences.
    -l (ell) One per line.
    -t Separate with tabs.
    -Nn Use n spaces (default 1).
    -L If -l is given, use line numbers.
    -o Output each character in octal.
    -x Output each character in hex.
    -v Make non-printing characters visible.
    -r The first argument is a regular expression. Print each string
    given as an argument that matches this regular expression.

    and no doubt people will want them. Is this necessary? echo -e is
    considered harmful (and when I started /bin/sh programming, I didn't
    like that it wasn't default. Oh well).

    The lesson?
    echo -n '-n
    '
    is the solution.



  16. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 2:58 PM, Pietro Gagliardi wrote:
    > Is there a valid reason to have echo process the arguments given?


    I'm leaning toward Eric's suggestion of splitting echo in twain. When
    facing south, the Plan 9 will open her mouth to echo nothing; when
    facing north (echo-n or echon or something) she won't.

    --Joel


  17. Re: [9fans] bug in echo?

    but
    echo -n '-n
    '
    is a hack.
    with a different implementation it might as well
    complaint that '
    ' is an invalid flag.

    And in any case, the "do the same thing the same way
    all the times" argument suggests that -- should terminate
    option processing. doesn't it?


  18. Re: [9fans] bug in echo?

    But should echo ignore arguments it doesn't understand (like UNIX
    does) or complain (like GNU echo does)? Also note this from the bash
    manual:

    echo does not interpret -- to mean the end of options.

    This is just a matter of the proper behavior to implement echo -- with.

    Using two programs is the approach that "Program Design in the Unix
    Environment" suggests taking in a time like this, but it breaks
    compatibility with previous versions of echo.

    There is no solution. Let us not forget:

    values of Δ will give rise to doom!

    On Mar 26, 2008, at 3:43 PM, Francisco J Ballesteros wrote:

    > but
    > echo -n '-n
    > '
    > is a hack.
    > with a different implementation it might as well
    > complaint that '
    > ' is an invalid flag.
    >
    > And in any case, the "do the same thing the same way
    > all the times" argument suggests that -- should terminate
    > option processing. doesn't it?
    >




  19. Re: [9fans] bug in echo?

    > values of Δ will give rise to doom!

    at least get that one right, please?

  20. Re: [9fans] bug in echo?

    On Wed, Mar 26, 2008 at 6:10 PM, erik quanstrom wrote:
    > >> this is a very odd case

    > >
    > > odd but important. it's worth knowing that

    >
    > what's your reasoning that this is an important case?


    i think it's important because every time you put
    echo $foo in a shell script, you're opening yourself
    to unexpected behaviour should the first member of $foo
    happen to become -n at some time.
    the possibility of a security hole via this mechanism is small
    but present (try grep 'echo[ ]+\$' /rc/bin/*)

    one can always do:

    echo -n $"foo^'
    '

    i suppose, but i doubt that anyone ever will.

    mind you, it's a lot better than interpreting backslash escapes a la sys v echo.


+ Reply to Thread
Page 1 of 3 1 2 3 LastLast