MacOS – Curl from Pastebin messes with carriage returns

command linemacos

Whenever I use curl to get a file like .profile from Pastebin, the .profile file isn't read properly. I did some checking, and it seems to be down to the carriage returns.

How do I solve this problem? Can I correct the carriage returns in transit?

Best Answer

For reasons that pass understanding pastebin.com raw mode uses Windows line endings - carriage return followed by linefeed - rather than plain linefeed that is used by all right thinking operating systems.

So you need to remove the carriage returns. The easiest way to do this is using tr.

curl https://pastebin.com/raw/qg0r3wt | tr -d '\r' > .profile

That will save the contents of the pastebin qg0r3wt into the file .profile with carriage returns removed.