redirecting standard error in Bash

This is a discussion on redirecting standard error in Bash within the Linux Programming forums, part of the Platform Specific Boards category; Hi, How do I redirect standard error in Bash? I know 2> is what you use in tcsh for redirecting ...

  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,493
    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-16-2002 at 12:57 AM.

  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 03: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, 12:48 PM
  2. array initialization & C standard
    By jim mcnamara in forum C Programming
    Replies: 2
    Last Post: 09-12-2008, 04:25 PM
  3. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 01:02 AM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 10:15 AM
  5. standard language, standard compiler?
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-03-2001, 05:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21