prasha6
prasha6

Reputation: 183

What happens when "\r\n" is used in a mac OS X?

What happens when "\r\n" is used in a mac OS X?

In Windows, it goes to the next line; but this can be done just with the '\n' in Mac OS X. What would happen if "\r\n" is used in a mac os x.

Upvotes: 3

Views: 3248

Answers (1)

Kiran Kulkarni
Kiran Kulkarni

Reputation: 199

It depends on where you use the \r\n

Text files: Modern text editors can automatically detect the line endings and display the content of the lines without any abnormal behaviour. They may additionally notify that the line endings are in DOS format somewhere in their notification/message bar

I am not sure about the default text editor included in Max OSX, but any text editor not capable of automatically detecting the type of line endings would show an additional character to represent the \r at the end of the lines Based on the capability of the text editor, these may be displayed as tiny opaque boxes with or without a 'CR' inside of them

Shell scripts: If the text files are actually used for shell scripting, then the additional \r will cause the scripts to fail with errors

dos2unix or d2u can convert the files from DOS format (\r\n) to unix format (\n) line endings

Side note, older versions of mac used \r for line endings

Upvotes: 4

Related Questions