Thread: redirecting standard error in Bash

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    11

    redirecting standard error in Bash

    Hi,
    How do I redirect standard error in Bash?
    I know 2> is what you use in tcsh for redirecting standard error to a file but what is it in Bash?
    What about standard output in Bash?

    Thanks

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    cat error >& output.txt
    that will redirect both standard output and standard error output to output.txt

    standard output is just plain old >

    //edit: 2> works with stderr only
    Last edited by ygfperson; 07-15-2002 at 11:57 PM.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    11
    ok thanks, now Ive moved on to the duplicate stuff where you use 2>&1 meaning 2 is the duplicate of 1
    what is happening with these two similar scripts using that example?

    2>&1 cat x junk 1> junk2

    1> junk2 2>&1 cat x junk

    Assume junk exists but file x does not exist

    Thanks

  4. #4
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    This does nothing: 2>&1 because the &1 references to itself.

    cat x junk 1> junk2
    This will print "cat: x: No such file or directory" and prints junk to junk2(because stderr is not redirected)
    Last edited by raimo; 07-16-2002 at 02:28 PM.
    I am not using Dev-C++.
    #!/usr/bin/env python
    import sys;file=open(sys.argv[0]);print file.read();file.close()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Standard efficiency
    By Jorl17 in forum C Programming
    Replies: 3
    Last Post: 06-18-2009, 11:48 AM
  2. array initialization & C standard
    By jim mcnamara in forum C Programming
    Replies: 2
    Last Post: 09-12-2008, 03:25 PM
  3. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  5. standard language, standard compiler?
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-03-2001, 04:21 AM