2009/4/3, Russ Cox <r...@swtch.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 > >
ok, thanks -- Hugo