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

        #include <u.h>
        #include <libc.h>

        /* 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.


Reply via email to