C shell question.

Mike Gogulski mjg at rtmvax.UUCP
Mon Feb 13 13:41:21 AEST 1989


In article <6295 at phoenix.Princeton.EDU> prnott at phoenix.Princeton.EDU () writes:
>
>	I hope this is the right news-group for this question -
>Could someone tell me how I can redirect output from standard error
>to a file or device?  In the Bourne shell, this can be achieved by
>
>	command 2>filename, but this doesn't work in the C shell.
>
>Does anyone know what the syntax is?  Thanks in advance.
>
>Prabhu.

Well, the syntax is is pretty simple. You can direct the stdout with
the following:

% command > file

You redirect the standard error in the same way.

% command >& file  <-- this puts BOTH the stderr and the stdout into
		       'file.'

These work with >> and >>& as well, for 'append to file.' However,
there is no easy way in csh to duplicate th effects of the following
sh command:

$ command 1>stdout 2>stderr,

because csh does either the stdout or both the stdout and the stderr.
If you want to put the stdout in one file and the stderr in another,
the way to go is something like this:

% ( command > stdout ) >& stderr

This, however, is kinda yucky. You might wish to look at Bob
Glickstein's "redir" program, recently posted to comp.sources.misc,
which allows redirection much like sh does.

	--Mike

+-----------------------------------------------------------------------------+
|        DISCLAIMER:        | Mike ...{uiucuxc|petsd}!peora!ucf-cs!ucfunix!mjg|
|   I Am _NOT_ The Walrus   | Gogulski ...{uiucuxc|petsd}!peora!rtmvax!mjg    |
+-----------------------------------------------------------------------------+
|   "The number of UNIX installations has grown to 10, with more expected."   |
|         (The _UNIX Programmer's Manual_, 2nd Edition, June, 1972.)          |
+-----------------------------------------------------------------------------+



More information about the Comp.unix.questions mailing list