Pipes and redirections in tcsh
A quick reference to pipes and redirections in tcsh
.
Pipes
Use the standard output of
program_1
as the standard input ofprogram_2
:program_1 | program_2
Use the standard and diagnostic outputs of
program_1
as the standard input ofprogram_2
:program_1 |& program_2
Redirections
Open file name as the standard input:
program < name
Use file name as the standard output:
program > name
Append the output to the end of file name:
program >> name
Route both the standard and diagnostic outputs to file name:
program >& name
Append both the standard and diagnostic outputs to file name:
program >>& name
Tips
To route the standard and diagnostic outputs to separate files, use the following syntax:
( program > outfile ) >& errfile
To route the diagnostic output to a file and the standard output to the terminal, use:
( program > /dev/tty ) >& errfile
To retain only the diagnostic output, redirect the standard output to
/dev/null
:program > /dev/null ( program > /dev/null ) >& errfile
In order to test pipes and redirections, use the following Perl program:
#!/usr/bin/perl print STDOUT "STDOUT: Standard output\n"; print STDERR "STDERR: Diagnostic output\n";
Comments
# Sandeep, November 14, 2003 at 11:04
How to send STDERR to /dev/null in tcsh?
# Olivier, November 14, 2003 at 11:49
Use this to send STDERR to /dev/null and STDOUT to the terminal:
Change /dev/tty to a file name to send STDOUT to a file.
Note to self: fix the comment system to allow the entry of code.
# Jesse Thompson, June 22, 2009 at 01:41
Thank you Oliver, this is a great piece of reference for the workings of Tcsh, which I am often forced to use in certain environments.
I have bookmarked it. ;3
—Jesse