Refresh - change my pseudo-comment to a real answer.
I think this answer should explain the behavior you see. In particular, the $() command substitution operators and return outputs will push new lines out of the output commands. However, the direct assignment in your second example does not perform any swap commands, so it works as expected.
Therefore, I am afraid to say that, in my opinion, the above comment that you refer to is incorrect.
I think the safest way to recover IFS is to install it in a subshell. All you have to do is put the appropriate commands in parentheses () :
( IFS=$'\n' echo -n "$IFS" | od -t x1 for file in `printf 'one\ntwo two\nthree'`; do echo "Found $file" done )
Of course, calling a subshell requires a little delay, so you need to consider performance if you need to repeat it many times.
As an aside, be very careful, file names can contain both \ b and \ n. I think that only about the only characters that they cannot contain is a slash and \ 0. At least that's what he says about this wikipedia article .
$ touch $'12345\b67890' $ touch "new > line" $ ls --show-control-chars 123467890 new line $
source share