I came across the following line of code (source):


I'm not quite sure how to interpret that line (specifically why there is a $ character before the newline). It seems like the "special variable" named IFS is being set to a variable named "the newline character"?

What does this line do, and what part of Bash allows this?

1 Answer 1


IFS=$'\r' set IFS variable to carriage return.

bash allows ANSI-C Quoting string. $'string' will expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.

  • How is that different from just doing IFS="\r"?
    – IQAndreas
    Commented Apr 4, 2015 at 16:45
  • @iqa IFS="\r" sets IFS to the two-character string backslash, r. IFS=$'\r' sets it to a one-character string, a carriage return. Commented Apr 4, 2015 at 22:41
  • @Gilles: oh, I only think in case double quotes, maybe I'm too sleep, thanks.
    – cuonglm
    Commented Apr 5, 2015 at 1:55
  • @Gilles Argh, I keep mentally picturing strings in Bash the way they are treated in ECMA-based languages. I need to stop doing that.
    – IQAndreas
    Commented Apr 5, 2015 at 5:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .