On Wed, Mar 26, 2008 at 8:43 PM, Francisco J Ballesteros <[EMAIL PROTECTED]> wrote: > but > echo -n '-n > ' > is a hack.
yes so is any of the other solutions, each with its own constraints. > with a different implementation it might as well > complaint that ' > ' is an invalid flag. no. This breaks unnecesarily: echo -a -a which is useful. The kind of change I was suggesting was minimal. Just solved the problem did not break anything else. The only thing it could have potentialy break was echo -- which before wrote -- and now writes only the newline. This could be easily solved by rewriting it as echo -- -- and I haven't seen any instance of this in /rc/bin (I looked even if it was not very carefully). The benefits of the change are easy to see. If you write echo -- anything you know the anything is now being echoed, whatever that is. > > 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? > Yes, it is probably true that another "if" to ignore -- after the -n could be added. I wrote it just as an example of how little change would be needed. The complete change to do it "right" would be again: (written as an example, untried and not being overly careful) #include <u.h> #include <libc.h> void main(int argc, char *argv[]) { int nflag, argi; int i, len; char *buf, *p; nflag = 0; argi = 0; if(argc > 1) if(strcmp(argv[1], "--") == 0) argi++; else if(strcmp(argv[1], "-n") == 0){ nflag++; argi++; if(argc > 2 && strcmp(argv[2], "--") == 0) argi++; } len = 1; for(i = 1+argi; i < argc; i++) len += strlen(argv[i])+1; buf = malloc(len); if(buf == 0) exits("no memory"); p = buf; for(i = 1+argi; i < argc; i++){ strcpy(p, argv[i]); p += strlen(p); if(i < argc-1) *p++ = ' '; } if(!nflag) *p++ = '\n'; if(write(1, buf, p-buf) < 0) fprint(2, "echo: write error: %r\n"); exits((char *)0); } -- - curiosity sKilled the cat