Tweeter buttonFacebook buttonLinkedin button
  • 15 Jul 2010 /  BASH, Programming

    Example:

    export IFS=$'\n'

    for i in $(find .);
    do
    echo LEXO$i
    done

    It work better for me under GNU/Linux Slackware, but is reported that under GNU/Linux Ubuntu it doesn’t work and the change for it is:

    Example:

    export IFS=$'
    ' # in the second line, generating the newline

    for i in $(find .);
    do
    echo LEXO$i
    done

    We can use hexadecimal too:

    IFS=$’\x20′ # Space
    IFS=$’\x09′ # Tab
    IFS=$’\x0A’ # Line Feed
    IFS=$’\x0D’ # Carriage Return

    Source:
    http://tldp.org/LDP/abs/html/internalvariables.html
    http://wikiri.upc.es/index.php/BASH_uso_IFS
    http://forum.soft32.com/linux2/Bug-409179-DASH-Settings-IFS-work-properly-ftopict70039.html

  • 28 Apr 2009 /  BASH, Programming

    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