From mboxrd@z Thu Jan 1 00:00:00 1970 Mime-Version: 1.0 (Apple Message framework v753) In-Reply-To: <2dccf442569c12a4ba9193abb0392726@quanstro.net> References: <2dccf442569c12a4ba9193abb0392726@quanstro.net> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Pietro Gagliardi Date: Wed, 26 Mar 2008 14:58:26 -0400 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Subject: Re: [9fans] bug in echo? Topicbox-Message-UUID: 827f9776-ead3-11e9-9d60-3106f5b1d025 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.