Question on the IFS variable (not a FreeBSD question)

Rakhesh Sasidharan rakhesh at rakhesh.com
Sun Aug 12 21:17:02 PDT 2007


Manolis Kiagias wrote:

> Do a little experiment (inspired from the post stated above):
> #export IFS="\n"
> #printf '<%s>\n' "$IFS" | cat -vt
> will give <\n> ==> not what you expect
> #export IFS='\n'
> #printf '<%s>\n' "$IFS" | cat -vt
> will give <\n> ==> again, not what you expect
> #export IFS=$'\n'
> #printf '<%s>\n' "$IFS" | cat -vt
> will give
> <
>>
> definitely a new line character (finally...)
> I am not certain of the explanation, but from the above it seems to me
> the IFS does not evaluate special '\something' characters unless there
> is a $ in front. That is, of course, what you would do to get the value
> of a shell variable. It seems then these characters need to be evaluated
> in the same way.

Yup, that's what I too figured from my experiments. Strange.

Oh well ... good to know now that '\n' (even in double quotes etc) need 
not always refer to the newline. Sometimes the $ magic is required ... :-)

Thanks!
Rakhesh


More information about the freebsd-questions mailing list