Subject: Re: Unixism, pipes and pkgsrc
To: Johnny Billquist <bqt@softjar.se>
From: Chavdar Ivanov <ci4ic4@gmail.com>
List: netbsd-users
Date: 08/23/2007 08:57:12
On 23/08/07, Johnny Billquist <bqt@softjar.se> wrote:
> Steven M. Bellovin skrev:
> > Let me add one more complexity: pipes.  If you want to send stderr in
> > to the pipe, you have to put the 2>&1 before the pipe:
> >
> >       foo 2>&1 | bar
> >
> > If you write
> >
> >       foo | bar 2>&1
> >
> > it will affect stderr for bar, not foo.
>
> That can't be right, can it?
> I would have thought it would be
>
> foo | 2>&1 bar

No, the latter just redirects stderr to stdout for the bar command.
The redirection can be at (almost) any place in the command string and
not only at the end, where it is normally found by convention - e.g.

# > /tmp/out 2>/tmp/err ls -d /tmp /nonex
zsh: exit 2     ls -d /tmp /nonex > /tmp/out 2> /tmp/err
# cat /tmp/err
/nonex: No such file or directory
# cat /tmp/out
/tmp


>

>
> The first example would be evaluated the same as mentioned before. stderr
> becomes a copy of stdout, and then you redirect stdout. That won't affect stderr.
>
> But I might be totally wrong here. I don't use sh myself, so I'm no expert...
> When it gets too complicated, I change to tcsh instead, in which I have a better
> understanding how things happen...

Since I read 'csh considered harmful'
(http://faqs.cs.uu.nl/na-dir/unix-faq/shell/csh-whynot.html), some 12
years ago, I haven't touched csh or any derivative of it.

>
>         Johnny
>
> --
> Johnny Billquist                  || "I'm on a bus
>                                    ||  on a psychedelic trip
> email: bqt@softjar.se             ||  Reading murder books
> pdp is alive!                     ||  tryin' to stay hip" - B. Idol
>

(BTW that remark about the pdp's is so very true - it wasn't that long
ago I had to help some hospital's scanner of some description sort out
it's RT-11 system...)

Chavdar Ivanov