In article <kiuu67$4lv$
1...@dont-email.me>, Joe Beanfish <joebe...@nospam.duh> wrote:
> On Wed, 27 Mar 2013 11:13:30 +0000, Avoid9Pdf wrote:
Thanks to Joe Beanfish for a competent explanation, but I've still got plenty
queries. My problem with the design of bash is subtle. Which is why noone
else raises it? They just keep their head down and march on.
A child can LEARN to parse the 4 word-sentence:
"Mis he will understand";
but only by considering the WHOLE sentence, BEFORE starting to parse;
so that it's seen that "Mis" is not resolved until "understand" is read.
In 'proper' languages [the algol-family, which probably includes C], we
handle this simply by stacking [where lisp is the extreme/obvious example].
So: REPEAT <lotaStuff> UNTIL <boolean>
is no problem, since the parser knows to stack/push "REPEAT" until the
<lotaStuff> is resolved and then 'continue'.
But for the 5 line script:----
cat>/tmp/mesgFile
( echo 'Read from stdin and write that to mesgFile'
echo 'Commands inside parens are run in another shell'
echo 'Set file-descriptor 3 to read/write the specified device'
) 3<>/dev/tcp/$smtp_server/25
Apparently line1 is complete/resolvable?
Line2 can't resolve until line5's closing-parens?
Line5 resolves line2 AND sets file-descriptor 3?
Is that right ?
If so, then the complete script must be COMPILED, and can't be interpreted
and run one-line-at-a-time ?
-- snip ---
> Given the [silly] shell command
> echo "Hello World" | cat >foo
> the shell tells the kernel to run programs "echo" and "cat" with the
> standard-output(stdout) of echo connected to the standard-input(stdin)
> of cat (see pipe(2) and pipe(7)). And the standard output of cat
> connected to file "foo". So when cat reads it's stdin it will see "Hello
> World" and dutifully write that to it's standard-output. Upon trying to
> read more it will find nothing, because echo didn't print more, and
> therefore quit. The result will be "Hello World" in the file foo.
>
That convolution completely throws me!
Here's how I've MIS-learned it.
echo "Hello World"
== puts "Hello World" to standard-out
> foo
== redirects the [output to standard-out] to device: foo
And I've always understood `cat` to be equivqlent to:
outport(PortNo, byte) in machime code; OR
Write(device, ByteString); with the distortion/morphing
that device = stdout, when omitted.
Then I find that NO! according to a deeper read of the man:
"Concatenate FILE(s), or standard input, to standard output."
Which means it's something like:-
IF args=Nill THEN print(keybrd)
ELSE ForAllArgsDO{
IF arg="-" THEN print(keybrd)
ELSE print(argN)
}
But even that's not enough!
You've come with a NEW syntax apparently undocumented
in `man cat`:-
] echo "Hello World" | cat >foo
where the input/argument doesn't appear after the 'verb'.
But the syntax of cat was determined independant and before
shell-redirection, so the shell should TAKE the existing syntax
and use that.
How does the shell morph the syntax of `cat`?!
This looks like FRAUD!! Where's the FBI?