bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read builtin. input processes improperly inheriting IFS setting


From: David H.
Subject: read builtin. input processes improperly inheriting IFS setting
Date: Sat, 27 Jul 2013 01:34:53 +0900

From: David H.
To: bug-bash@gnu.org,bash@packages.debian.org
Subject: read builtin. input processes improperly inheriting IFS setting

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include
-I../bash/lib  -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall
uname output: Linux mybox 3.2.0-3-686-pae #1 SMP Thu Jun 28 08:56:46
UTC 2012 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 4.2
Patch Level: 45
Release Status: release

Description:

    When the read builtin is prefixed by an IFS setting, for field
splitting, and the input involves an unquoted variable expanded inside
a herestring, command substitution, or process substitution, the
contents of the variable are split by that IFS setting before being
read. This results in all input being stored in the first variable.

    It is my understanding that redirection patterns like these should
be considered independent processes and not subject to the environment
settings of the target command.

    The expected behavior appears if a heredoc or compound command is
used. ksh also shows the expected behavior for all attempted patterns.

    Quoting the input variable also worked in all cases.

Repeat-By:

    # The test string:
    $ echo $instring
    root:x:0:0:root:/root:/bin/bash

    # Gives incorrect (unexpected) output:
    $ ( IFS=: read -a strings < <( echo $instring ) ; printf '[%s]\n'
"${strings[@]}" )
    [root x 0 0 root /root /bin/bash]

    # Gives expected output
    $ ( IFS=: read -a strings ; printf '[%s]\n' "${strings[@]}" ) < <(
echo $instring )
    [root]
    [x]
    [0]
    [0]
    [root]
    [/root]
    [/bin/bash]


    # Some other patterns that fail in the same way:
    $ IFS=: read -a strings <<<$instring
    $ IFS=: read -a strings <<<$( echo "$instring" )
    $ IFS=: read -a strings <<<"$( echo $instring )"
    $ IFS=: read -a strings <<<$( IFS="" ; echo $instring )

    # Other patterns that appear to work properly:
    $ IFS=: read a b c d e f g <<END
    > $instring
    > END

    $ IFS=: read a b c d e f g < <( IFS=""; echo $instring )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]