Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was trying to change the IFS(Internal Field Separator) character to comma for a file processing, but to my surprise the IFS was un-changed.

Here's the order of commands and output :

mtk4@mtk-laptop:~$ echo .$IFS.
. .                                    # A space
mtk4@mtk-laptop:~$ IFS=","             # No error was thrown, no message
mtk4@mtk-laptop:~$ echo .$IFS.
. .                                    # Again echo'd it, but no change

Please let me know, what is wrong here?

share|improve this question
For future reference, echo is not a reliable way to inspect unknown variable values. A much safer and more foolproof method would be something like printf %s "$var" | od -t c or your hex dumping tool of choice, to catch any unprintable ones. The default value of IFS should be space, tab, newline. – jw013 Oct 18 '12 at 19:47
Interestingly, zsh prints IFS properly with echo, but bash doesn't. – Kevin Oct 18 '12 at 20:47
@Kevin That's because in zsh, variables's values do not undergo word splitting (this is zsh's most salient incompatibility with Bourne/POSIX shells). You'll see the same effect under emulate sh or with echo .$=IFS. – Gilles Oct 18 '12 at 23:38
up vote 6 down vote accepted

IFS is also used as a separator when expanding a $variable with no quotes around it. In other words, you did change it, but, it got treated as a separator between the two dots. And, the echo command doesn't know what your $IFS is, and even if it did, it doesn't put it between its arguments for output, so you got a space there. Try echo ".$IFS."

share|improve this answer

Using bash you can use the builtin printf command with the %q format specifier to inspect the value of the IFS variable (see help printf).

printf '%q\n' "$IFS"    # $' \t\n'

# alternative, as already suggested by jw013
printf '%s' "$IFS" | od -A n -t x1 | xargs     # 20 09 0a
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.