On Mon, Nov 22, 2010 at 8:37 AM, rajeevrkv wrote:

> Aah, the subtleties of shell plumbing....

The way that plumbing works is fabulous. (I had read about this to an
extent, but there were more details as you've explained below)

> $ cat < foo
> bash: foo: No such file or directory

Yes, I failed to notice the difference initially, though I knew that
'<' will cause an input to be redirected from the file to STDIN of
process. (cat)

> $ cat < foo 2> error
> bash: foo: No such file or directory
>
> Remember, bash has no idea when the process may be expecting the input, it
> just has to keep it available on the STDIN fd for whenever the process asks
> to read it. In order to do that, bash FIRST creates the fd pointing to the
> file, then creates the fd redirecting STDERR to another file and then
> finally starts the process with the redirection in place. Now, if the
> initial creation of the fd does not take place, "bash" thrown the error on
> it's STDERR fd, not the STDERR fd of "cat"(Actually, the cat process is not
> actually even started, since the redirection setup failed.) That's why the
> redirection of the "cat" process STDERR does not capture the errror message.

Thanks for the detailed explanation I did understand what you said.
(Bash expands the meta-characters first and then processes the
command).

So effectively, whenever, we are redirecting to STDOUT or STDERR, the
command (process) that is executed, its output or error is put into a
file. Anytime, the input for bash fails (via file through < operator),
the subsequent STDOUT and STDERR are reverted to usual (the terminal)
[even if appeared to be changed in the actual command].

> I hope that this makes shell redirection a
> little clearer for you.

It does. It gives me more insight into the way Bash works. If there's
a book / link, which provides such details with examples, I'll be able
to understand bash better than I currently do.

Thankyou very much. You've been a patient guy in explaining all this.
(I remember / know you when I met you at one of the colleges
explaining students about Fedora Linux) :)

--
Roshan Baladhanvi
-- 
http://mm.glug-bom.org/mailman/listinfo/linuxers

Reply via email to