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?


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.

|improve this answer|||||
  • How is that different from just doing IFS="\r"? – IQAndreas Apr 4 '15 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. – Gilles 'SO- stop being evil' Apr 4 '15 at 22:41
  • @Gilles: oh, I only think in case double quotes, maybe I'm too sleep, thanks. – cuonglm Apr 5 '15 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 Apr 5 '15 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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