From: Russ Cox <rsc@swtch.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] rc output redirection
Date: Fri, 3 Apr 2009 16:13:38 +1100 [thread overview]
Message-ID: <dd6fe68a0904022213n44b2cc9dodd748d5396cfd119@mail.gmail.com> (raw)
In-Reply-To: <138575260904020956l6cee2941mb542ece7ba46a8b6@mail.gmail.com>
> But when you do something like
> cmd1 | cmd2 |[2] cmd3
> you get cmd1's stdout piped to cmd2's stdin; but my confusion begins
> here: is it cmd1's or cmd2's stderr that gets redirected to cmd3's
> stdin? maybe both? my guess is that ...
why guess?
% {echo cmd1 >[1=2]} | {echo cmd2 >[1=2]} | sed 's/^/cmd3: /'
cmd1
cmd2
% {echo cmd1 >[1=2]} | {echo cmd2 >[1=2]} |[2] sed 's/^/cmd3: /'
cmd3: cmd1
cmd3: cmd2
%
not what i expected, but there you have it.
and it makes sense: cmd1 and cmd2 are both
writing to the same stderr, so redirecting it
redirects both.
> how can I redirect cmd1's stderr to cmd3's stdin instead
> of cmd2's? or both?
if you don't care about cmd2's stderr, then you can get rid of it
% {echo cmd1 >[1=2]} | {echo cmd2 >[2]/dev/null} |[2] sed 's/^/cmd3: /'
cmd2
cmd3: cmd1
%
> It's easy to think of more complex cases.
it's easy to think of elephants.
rc does its general-purpose job very well.
if you have special-purpose needs,
as lucio suggests, write a c program.
russ
next prev parent reply other threads:[~2009-04-03 5:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-02 16:56 hugo rivera
2009-04-02 17:28 ` lucio
2009-04-03 5:13 ` Russ Cox [this message]
2009-04-03 8:51 ` hugo rivera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dd6fe68a0904022213n44b2cc9dodd748d5396cfd119@mail.gmail.com \
--to=rsc@swtch.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).