Tweeter buttonFacebook buttonLinkedin button



BASH I/O stdout, stdin, and stderr

Some times we don’t want that command print out messages, and we need to clean all out messages (error or standard out) that it generates. For to solve this, we are going to use the I/O facility provided by BASH.

BASH provide 3 file descriptors, and they are:
0 – stdin – Used for get data.
1 – stdout – Used for write standard data into screen.
2 – stderr – Used for write error messages into screen.

So, using redirector (>) we can redirect(obviously) this data/messages wherever we want and also files.

Examples:
¿How to redirect error messages(stderr) to standard out(stdout)?

ls this.file.doesnt.exist 2>&1

¿How to redirect error messages(stderr) to limbo(/dev/null)?

ls this.file.doesnt.exist 2> /dev/null

¿How to redirect error(stderr) and standard out(stdout) messages to limbo?

ls this.file.doesnt.exist &> /dev/null
or
ls this.file.doesnt.exist 2> /dev/null 1>&2

0 Responses to “BASH I/O stdout, stdin, and stderr”


  1. No Comments

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Slideshow

Get the Flash Player to see the slideshow.

 

April 2009
M T W T F S S
« Mar   May »
 12345
6789101112
13141516171819
20212223242526
27282930