Quote:
Originally posted by nic39
Thank you.
I do however think that tmp file is a problem, in my case.
I also did not want to merge stdout and stderr.
|
First off, 2>&1 does not *merge* stdout and stderr, it simply tells the shell that fd2 should adopt the behaviour of fd1. Often this would mean that stdout and stderr would in fact be merged but if you're trying to do what we are here and direct stderr down a pipe, you would have to get fd2 to temporarily behave like fd1, while telling fd1 to behave like another file descriptor (or to go to a file).
Anyhow, the original solution I gave you is flawed. If CMD2 has std output, this would be passed down the pipe to CMD3 which we don't want. I tested using 'mail', so I didn't notice - Ooops!
This should work though (and it doesn't use a temp file!)...
Code:
{ CMD1 | CMD2 2> /dev/null; } 3>&2 2>&1 1>&3 | CMD3
Here we introduce fd3 so that we can swap the behaviour of fd1 and fd2 around. You might want to consider where you send stderr from CMD2 'cos I don't think you'd really want it going to /dev/null.
Damian