Home Man
Search
Today's Posts
Register

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in the UNIX for Beginners Questions & Answers forum.

/dev/null 2>&1 question

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 04-29-2003
/dev/null 2>&1 question

Hi,

suppose you have the following line at your crontab :

5 * * * * /usr/mine/script > /dev/null 2>&1

now i understood that the " > /dev/null 2>&1 outputs both Standard outpout and Standard Error messages to the /dev/null device or file...

the first part , " > /dev/null " transfers the stdout messages to the /dev/null, but i am missing the part where the stderr is also dumped at dev/null.....

2(is stderr) >(send) &1 (stdout)...

i am not understanding how you send stdout first to dev/null and then send stderr to stdout which in turn will be sent to dev/null too ???

Thanks.
# 2  
Old 04-29-2003
There is a system file table. It has one entry for every open file. Your process has descriptors that point to file table entries. Let's change the example to a text file.

So the shell syntax starts out " > results.txt". To run that the shell will need to do something like:
close(1);
fd=open("results.txt", O_WRONLY, 0);
We actually had to open a file. This filled in a file table entry. And now fd 0 points to that file table entry.

Now the syntax continues "2>&1" and to run that, the shell does something like:
close(2);
fd=dup(1);
Here we don't open a file. It's just that whatever file table entry fd 1 was pointing to has been copied into fd 2.

There is more to this than just saving an expensive open call. If we write to fd 1, what ever we write goes into the file. If we then write some more, the new data goes at the end of the file. We can write to fd 1 and we can write to fd 2 and they don't step on each other. That's because a write to either fd updates the file pointer in the file table entry.

In contrast, " > results.txt 2 > results.txt" gives us two file table entries and two file pointers.
 

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Redirecting standard out to /dev/null goes to file "/dev/null" instead jbmorrisonjr Shell Programming and Scripting 5 06-06-2012 07:27 PM
Question on NULL and zero value of variable spynappels Shell Programming and Scripting 7 09-28-2011 09:32 AM
Newbie question: if[command not null] zangarules Shell Programming and Scripting 13 04-13-2011 04:28 PM
/dev/null 2>&1 Versus /dev/null 2>1 glev2005 UNIX for Dummies Questions & Answers 3 03-08-2011 01:20 PM
Insert string 'NULL' where there is a null value zilch Shell Programming and Scripting 8 05-27-2010 09:17 AM
Question about NULL Character & fgets() f.ben.isaac Programming 2 11-04-2008 11:31 AM
/dev/null what is the use of it? webmunkey23 Shell Programming and Scripting 3 07-03-2008 07:47 AM
compare null with non-null nitin Shell Programming and Scripting 8 11-04-2006 06:58 PM
> /dev/null rrs Shell Programming and Scripting 2 06-19-2006 04:29 AM
Null Value Khoomfire UNIX for Advanced & Expert Users 1 04-10-2006 09:55 AM


All times are GMT -4. The time now is 09:42 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password