Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to redirect stderr to a pipe and stdout to a file?



On Sun, Jun 15, 2003 at 02:50:30PM +0200, Haakon Riiser wrote:
> In bash, I could always do
> 
>   $ ls INVALID . 2>&1 >/dev/null | less
> 
> to send stderr:
> 
>   ls: INVALID: No such file or directory
> 
> to the less buffer and stdout to /dev/null.  When I use the
> same command in zsh 4.0.6, _both_ stderr and stdout is sent
> to less.  If I remove "| less" from the command, it works as it
> should:  stdout is discarded and stderr is sent to the terminal.
> I've looked through the chapter on redirection in zshmisc(1),
> but I couldn't find an answer.  (Of course, that doesn't mean
> it's not there. :-)
> 
> Thanks in advance for any help.

I don't know what the real answer is, but a workaround (which should
also work in bash) is to execute the first command in a subshell, i.e:

( ls INVALID . 2>&1 >/dev/null ) | less



-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@xxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author