Twitter Updates

    follow me on Twitter

    G-AVLN in front of her home

    G-AVLN in front of her home

    Mostly Unix and Linux topics. But flying might get a mention too.

    Sunday, November 19, 2006

    The IFS mystery

    The IFS is involved in the parsing of the command line (word splitting) and in variable assignment during the read built-in execution.

    But there is a side effect, which I have only discovered recently, by accident. If you assign positional parameters with set:

    $ set a 'b c' d 'e f'

    than using the * parameter we can get at the values individually or as one word. To illustrate, try the following:

    $ echo $* "$*"

    a b c d e f a b c d e f

    However, if you 'nullify' the IFS variable:

    $ IFS=""

    then the behaviour of the shell when referencing the * parameter changes:

    $ echo $* "$*"

    a b c d e f ab cde f

    This only works with the * parameter (not with @) and only if IFS had a null value (if you inset IFS altogether, then the shell will use a space to separate positional parameters.

    Finally, I've checked this behaviour in ksh and bash - same (and documented in manual pages, at least in bash).

    No comments:

    Blog Archive