« August 5, 2004 | Main | August 10, 2004 »

August 9, 2004

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 of program_2:

    program_1 | program_2
    
  • Use the standard and diagnostic outputs of program_1 as the standard input of program_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";
    

Knowledge base migration

I have decided to move my knowledge base to my main blog. The benefits are threefold:

  • I can repost knowledge base articles and give the impression that I update my blog more often;
  • Since I post other things here, it becomes less visible that I very rarely update the knowledge base;
  • I save one blog for when I upgrade to Movable Type 3

I will start moving the articles right now, starting with the most popular one: Pipes and redirections in tcsh. Of course, the old knowledge base permalinks will still work, long live mod_rewrite.

Do not meddle in the affairs of Coding Ninjas, for they are subtle and quick to anger.