Subject: Re: Unixism, pipes and pkgsrc
To: Chavdar Ivanov <ci4ic4@gmail.com>
From: Johnny Billquist <bqt@softjar.se>
List: netbsd-users
Date: 08/23/2007 22:30:00
Chavdar Ivanov skrev:
> 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.

Thanks for confirming that.

> 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 point is that when you give 2>&1 it means that stderr will be copied from 
stdout at that specific time, so if stdout is *later* changed, that change will 
not affect stderr, which will remain whatever stdout was previously.

>> 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.

You know the fine thing about religion? Everyone have one. :-)
Personally I think sh and it's derivates are jokes invented to punish people. :-)
Give me (t)csh any day of the week, and I'll be happy. But I won't prevent 
others from using sh, and won't try to convert them. And I expect the same in 
return.

> (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...)

Still do work on RSX systems here. And you can still buy new pdp-11s as well, if 
you really want to.

	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