Tweeter buttonFacebook buttonLinkedin button
  • 28 Apr 2009 /  BASH, Programming No Comments

    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

    Posted by lexo @ 5:59 pm

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image