Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    question on scripting

    from time to time I see something like this:

    test.ksh > test.log 2>&1

    the question is, what does "2>&1" mean?


  2. #2
    Linux Guru
    Join Date
    Oct 2007
    Tucson AZ
    I googled
    2>&1" mean?
    Found quite a number of sites, some with simple explanations, some with convoluted and/or detailed. Here's one explanation:

    The incantation 2>&1 means “Send errors (output stream number 2) to the same place ordinary output (output stream number 1) is going to.” By the way, this 2> jazz only works in the Bourne shell and its descendants. The C shell makes it annoying to separate errors from output, which is one of the reasons people avoid programming in it.
    I had no clue before reading your post and doing a search. Got the above from the Linux Journal site below which has lots more info:

    Beyond Your First Shell Script | Linux Journal

  3. #3
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Boston, MA
    Yeah, basically there are three "standard" streams of information. Standard input, standard output, and standard error.

    So for example, if you used the ls command to list contents of a directory, the results are standard output and defaults to printing to the screen.

    If you piped that standard output to a search command, say grep as so
    ls | grep Movies
    The output of ls becomes the standard input of grep.

    Standard error outputs diagnostic and error messages, which frequently you don't want. This is frequently directed to /dev/null, basically sending it off into nothingness.

    In some cases maybe you want standard output and errors printed to the screen, or you want the program to be quiet and send both of those to /dev/null, or send them to a log file, or whatever.

    Standard streams - Wikipedia, the free encyclopedia
    Cool Solutions: /dev/null
    BASH Programming - Introduction HOW-TO: All about redirection

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts