2>&1 |tee && 2>&1 >out

2>&1 |tee && 2>&1 >out

Post by Ajay Mata » Thu, 18 May 2000 04:00:00



Hi Shell Gurus:

 I am all confused here. Consider the following two commands:

 $ cmd 2>&1 | tee logfile

 $ cmd 2>&1 > logfile

 In the first case both stderr and stdout go to the logfile but not in the
second case. Can someone explain me the reason. This is ksh 93. Is the
shell smart to look ahead of 2>&1 construct to see if the output is
actually going to a pipe??

 Thanks
 -Ajay

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Ajay Matai   Email: matai<at>bigfoot<dot>com

 
 
 

2>&1 |tee && 2>&1 >out

Post by Ken Pizzi » Fri, 19 May 2000 04:00:00


On Wed, 17 May 2000 17:03:14 -0700,


> I am all confused here. Consider the following two commands:

> $ cmd 2>&1 | tee logfile

> $ cmd 2>&1 > logfile

The behavior of first line is a little counter-intuitive at
first.  The redirection operators for a simple command are
processed left-to-right, but the implicit redirection for the
pipe is done before any explicit operator.

Thus the sequence for the left-hand side of your first line is:
  0. redirect stdout (fd 1) to go down the pipe
  1. make fd 2 be a clone of the current fd 1
resulting in anything which is written to either stdout or stderr
to flow down the pipe.

For your second line it's:
  1. make fd 2 be a clone of the current fd 1
  2. redirect stdout (fd 1) to go to logfile
thereby redirecting stderr to go to the parent shell's stdout
and stdout to go to logfile.

So, for practice, what is the effect of:
  $ cmd 2>&1 > altlog | tee logfile
?

                --Ken Pizzini

 
 
 

2>&1 |tee && 2>&1 >out

Post by Matthew Land » Fri, 19 May 2000 04:00:00



> For your second line it's:
>   1. make fd 2 be a clone of the current fd 1
>   2. redirect stdout (fd 1) to go to logfile
> thereby redirecting stderr to go to the parent shell's stdout
> and stdout to go to logfile.

>                 --Ken Pizzini

Right.  To get what was originally wanted you would use

cmd >logfile 2>&1

Otherwise cmd 2>&1 1>logfile points descriptor 2 onto stdout, then
points descriptor 1 to the logfile.  However, 2 is still pointing to
stdout since you cloned descriptor 1 when IT pointed to stdout.  I
understand this but got confused by kens statement.  

     thereby redirecting stderr to go to the parent shell's
     stdout and stdout to go to logfile.

Don't think that redirecting stderr to stdout locks that descriptor
to ANOTHER descriptor that is also pointing to stdout.

 - Matt

 
 
 

1. HELP: 2>&1 > /dev/null != 2>&- > /dev/null ???

In /bin/sh, I tried to redirect the standard error and standard output to
/dev/null.

I still has the error message from the following command:

        ls /xyz 2>&1 > /dev/null

but not from the following command:

        ls /xyz 2>&- > /dev/null

I thought >&1 is the same as >&-. Any comments are appreciated.

Thank you.

Larry

2. Can't install xfstt (error in shared library)

3. *&& << 1GB >> Flash Memory Drive (&(*

4. How to make a script with a menu??

5. Help: Web Browser prob

6. &&&&----Looking for a unix shell------&&&&&

7. Nice level on proftpd

8. ppp && PPPoE && ADSL && net && buffer(s)

9. &#27809;&#26377;&#20154;&#29992;&#20013;&#25991;&#21527;&#65311;

10. sh/ksh 1>&2 2>&1 !%^%#!!?

11. &&&&&& SUGGESTION ??? &&&&&&&&

12. Palm & GSM & V.110 & IDSN -> Kernel Oops