shell - temp IFS as newline only. Why doesn't this work: IFS=$(echo -e '\\n')
I'm trying to use for in the shell to iterate over filenames with spaces. I read in a stackoverflow question that IFS=$'\n' could be used and that seems to work fine. I then read in a comment to one of the answers that to make it posix compatible for shells other than bash one could use IFS=$(echo -e '\n') . The former works but the latter doesn't. The comment is upvoted several times. I checked the output and the variable doesn't seem to contain the newline. #!/bin/sh IFS=$(echo -e '\n') echo -n "$IFS" | od -t x1 for file in `printf 'one\ntwo two\nthree'`; do echo "Found $file" done echo IFS=