ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1) When running a script and it is piped to /dev/null &, what is it mean ?
/usr/local/sbin/quotacheck1 > /dev/null &
2) When running a script and it is piped to /dev/null, what is it mean ?
killall checkin2.sh > /dev/null
3) When running a script and it is piped to /dev/null 2>&1 &, what is it mean ?
What is a 2 for ?
What is a &1 for ?
What is a & that goes after a 1 means ?
/etc/checkin2.sh > /dev/null 2>&1 &
/dev/null is like a black hole - everything you send there disappears.
>/dev/null means to redirect the output to go to /dev/null -- in other words not have coammnd out appear on the screen
The ampersand at the end of a line means to execute the line in a background process.
> /dev/null 2>&1 &
means: send standard output to the bit bucket (/dev/null), plus whatever would come out on stderr (2 - standard error output) make that go wherever stdout ( 1 - standard output ) is going. & at the end of the line = run in background. the &> is called a dup (for duplicate): creating a duplicate file descriptor, in this case, whatever goes to 2 ends up in 1
0 - stdin
1 - stdout
2 - stderr
Last edited by jim mcnamara; 04-20-2004 at 12:54 PM.
1) The output just gets sent into oblivion. The ampersand sends the command into the background.
2) See above minus the backgrounding
3) The last ampersand backgrounds the task. 1=stdout (standard output stream) and 2=stderr (standard error stream). "2>&1" redirects messages from stderr to stdout.
Redirecting (the > symbol) makes all standard output from the program go to the specified file. Redirecting to /dev/null means to send the output to oblivion. So basically the script doesn't want any of the output from quotacheck1, etc. to be shown.
The & at the end of a line tells the shell to run the program in the background. Otherwise you would have to wait for the program to finish before you got a prompt back again.
The 2>&1 redirection means to send standard output and error output messages to the file (/dev/null = oblivion).
Thank you jim mcnamara and david_ross for your help.
"2>&1" redirects messages from stderr to stdout.
Is it true that the standard in is by default the screen which is the terminal where the user type it in on a keyboard ?
Is it true that the standard out is by default the screen when 2>&1 is used?
Is it true that the standard error is by default the screen when 2>&1 is used?
Originally posted by Linh Is it true that the standard out is by default the screen when 2>&1 is used?
Is it true that the standard error is by default the screen when 2>&1 is used?
Yes, but both are also true when 2>&1 is not used.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.