[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: |& in bash?

From: Steven W. Orr
Subject: Re: |& in bash?
Date: Tue, 22 Jan 2013 06:56:31 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 1/21/2013 1:20 PM, John Caruso wrote:
In article <address@hidden>, Dan Douglas wrote:
It isn't very common to dump multiple streams into one pipe.

echo "n't very"  >/dev/null 2>&1

I suggest avoiding |&.

Personally I wouldn't use it in scripts, since I try to stick as close
to plain vanilla Bourne shell as possible (though that's not as much of
a consideration these days as it used to be).  But for interactive use
it's one of the greatest shell time- and effort-savers I know of, and
I'm very happy to hear it's made its way into bash.  I wouldn't suggest
avoiding it unless you like carpal tunnel.

- John

Just an old observation. I much prefer use of |& for the simple reason that it provides greater consistency.

foo > out 2>&1
The above uses the file out to capture stdout and stderr. The order of evaluation is important and if you were to say
foo 2>&1 > out
it wouldn't work because you would be redirecting stderr to stdout before stdout was redirected to a file.

By that logic,

foo 2>&1 | bar

should not work, but it does. It takes stderr and dups it to stdout, and *then* takes stdout and send it to a pipe.

The proper way that it should have been done (if I was Emperor of the Universe) would have been

foo | 2>&1 bar

I accept that the | delimits what happens in the two different processes, so this is not material subject to a jihad. Just an observation from a language lawyer.

Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

reply via email to

[Prev in Thread] Current Thread [Next in Thread]