On Sat, Jul 27, 2013 at 01:34:53AM +0900, David H. wrote:
> # 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]
You must quote "$instring" to prevent word splitting by the shell.
IFS=: read -a strings < <(echo "$instring")
or
IFS=: read -a strings <<< "$instring"
Your unquoted $instring is being split into fields by bash, which is
operating with IFS=: at that point. Quoting it avoids this problem.
imadev:~$ instring="root:x:0:0:root:/root:/bin/bash"
imadev:~$ IFS=: read -a strings < <(echo "$instring")
imadev:~$ printf '<%s> ' "${strings[@]}"; echo
<root> <x> <0> <0> <root> </root> </bin/bash>