read and IFS

Hi,

This is out of curiosity:
I wanted to extract year, month and date from a variable, and thought that combining read and IFS would help, but this doesn't work:

echo "2010 10 12" | read y m d

I could extract the parts of the date when separated by a -, and setting IFS in a subshell:
r=$(echo '2010-10-12' |(IFS='-'; read y m d; echo $y $m $d))

Any explanation why the first doesn't work?

Thanks

Rapha�l

In ksh:

echo "2010 10 12" | read y m d

In Bash (and newer ksh's):

read y m d <<< "2010 10 12"

Using IFS:

echo '2010-10-12'  | IFS='-' read y m d
echo $y $m $d
2010 10 12

IFS='-' read y m d <<<  "2010-10-12"
echo $y $m $d
2010 10 12


Thanks scottn for the clarifications.
Any idea why read <<< behaves differently from echo "" | read

Raph

Hi.

The bash manpage describes <<< as a "here string", a variant of a here document.

echo ... | read ... is just a plain old pipe.