Date: Tue, 27 May 1997 11:09:20 +0200 (MET DST) From: Zahemszky Gabor <zgabor@CoDe.hu> To: freebsd-questions@freebsd.org (FreeBSD questions) Cc: ATuretta@stylo.it, un_x@anchorage.net Subject: Re: What command line to redirect 'make world' warnings ? Message-ID: <199705270909.LAA00404@CoDe.hu> In-Reply-To: <31EBCC36B676D01197E400801E032495021F4A@STYLOSERVER> from Angelo Turetta at "May 26, 97 09:36:00 pm"
index | next in thread | previous in thread | raw e-mail
> I've run:
>
> make world 2>&1 > /proxy/world3
>
> and I would expect both stdout and stderr to go to file /proxy/world3.
> Instead, warnings & errors continue to be directed to my tty.
>
> What should be the right command line ? (I'm using bash)
1)
As somebody else said it, the correct form is:
make world > /proxy/world3 2>&1
because redirection occures (most of the times) from left to right.
So, in your version:
stdout goes to tty
stderr goes to tty
redirection 2>&1
stderr goes to the same place as stdout, which is (of course) tty
redirection > file
stdout goes to file
With the correct version:
redirection > file
stdout goes to file
redirection 2>&1
stderr goes to the same place, as stdout, which is (now) file
This type of redirection is working on all of the Bourne-shell-like
shells (sh/ksh/pdksh/bash/zsh)
2)
RTMF! from bash manual:
---
Note that the order of redirections is significant. For
example, the command
ls > dirlist 2>&1
directs both standard output and standard error to the
file dirlist, while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist, because
the standard error was duplicated as standard output
before the standard output was redirected to dirlist.
....
Redirecting Standard Output and Standard Error
Bash allows both the standard output (file descriptor 1)
and the standard error output (file descriptor 2) to be
redirected to the file whose name is the expansion of word
with this construct.
There are two formats for redirecting standard output and
standard error:
&>word
and
>&word
Of the two forms, the first is preferred. This is seman-
tically equivalent to
>word 2>&1
This type of redirection is working only in bash (and not in any other
sh-like shells - as I know -, but it works with csh, and other csh-like
versions - tcsh, itcsh (I think, I've newer used itcsh)).
3)
If you like, you can use your method, but with some minor corrections:
( make world 2>&1 >> /proxy/world3 ) > /proxy/world3
or
{ make world 2>&1 >> /proxy/world3 ; } > /proxy/world3
Of course, without the parentheses, it doesn't work (well, it shouldn't),
and you have to use append ( >> ) inside. Well, why? It's your exercise.
Bye, Gabor
--
#!/bin/ksh
Z='21N16I25C25E30, 40M30E33E25T15U!' ;IFS=' ABCDEFGHIJKLMNOPQRSTUVWXYZ ';set $Z;for i { [[ $i = ? ]]&&print $i&&break;[[ $i = ??? ]]&&j=$i&&i=${i%?};typeset -i40 i=8#$i;print -n ${i#???};[[ "$j" = ??? ]]&&print -n "${j#??} "&&j=;typeset +i i;};IFS=' 0123456789 ';set $Z;X=;for i { [[ $i = , ]]&&i=2;[[ $i = ?? ]]||typeset -l i;X="$X $i";typeset +l i;};print "$X"
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705270909.LAA00404>
