LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   2>&1 ? (https://www.linuxquestions.org/questions/linux-newbie-8/2-and-1-a-140956/)

dominant 02-01-2004 06:01 AM

2>&1 ?
 
Could anyone tell me what 2>&1 means?

jim mcnamara 02-01-2004 06:51 AM

What it actually does is a little confusing. The result is easy to understand.

Those numbers are file descriptors that exist for bash by default. 1 is stdout the terminal. 2 is stderr where all errors are reported.

What this does is to write error messages to the same place regular output goes, combining both into one stream. For example when you run a job, you may want to keep the good out and also save any error messages all at the same time -- all in one file.

jim mcnamara 02-01-2004 06:52 AM

Technically, the & calls the dup() function.

You can look up dup in the manpages.

mikshaw 02-01-2004 06:53 AM

It's a redirect.
2 represents stderr and 1 is stdout

Check out Bash-Prog-Intro-HOWTO for more info

again....i type so slowly.....

dominant 02-01-2004 07:04 AM

For example, i have seen the 2>&1 in scripts which are run through cron.

Then if an error occur then a console will open automatically reporting the error.

Am i right?

delta9 02-01-2004 07:50 AM

Quote:

Originally posted by dominant
For example, i have seen the 2>&1 in scripts which are run through cron.

Then if an error occur then a console will open automatically reporting the error.

Am i right?

If you redirect stdout (standard output) to a file by using "./program 1>file" and you want the errormessages of the program to go to the same file you use "./program 1>file 2>&1"

If stdout is your screen then errormessages will go to the screen too when using 2>&1


All times are GMT -5. The time now is 05:54 PM.