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”