On Sunday, 7 July 2013 at 20:08:19 UTC, Leandro Lucarella wrote:
Andrei Alexandrescu, el 7 de July a las 09:06 me escribiste:
On 7/7/13 8:55 AM, Andrei Alexandrescu wrote:
>Here's a conformant implementation for reference:
>http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c
Hmm, that's actually not so good, it doesn't ensure that I/O
was
successful. Anyhow, here's a possibility:
import std.stdout;
void main(string[] args)
{
const appendNewline = args.length > 1 && args[1] == "-n";
foreach (i, arg; args[appendNewline + 1 .. $])
{
if (i) write(' ');
write(arg);
}
if (nl) writeln();
}
But then I figured echo must do escape character processing,
see
e.g.
http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html.
With that the blog entry would become quite interesting.
If you want the specification, here it is :)
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
I prefer this one :p http://www.gnu.org/fun/jokes/echo-msg.html
From the opengroup spec:
"If the first operand is -n, or if any of the operands contain a
<backslash> character, the results are implementation-defined."
Ah...specifications...
I'm gonna stick with normal linux implementation, as described
here: http://linux.die.net/man/1/echo
However, on my machine, "echo --version" claims it's part of the
GNU coreutils, but when you look at the coreutils docs:
http://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html#echo-invocation
You get the sentence "the normally-special argument ‘--’ has no
special meaning and is treated like any other string.", which
should preclude the identifying message being printed in the
first place!