Jan 21, '04 09:17:00AM • Contributed by: LightYear
The issue of line endings in OS X can be complicated since UNIX uses a line feed (LF, 0x0A in ASCII) for an end-of-line, and Macintosh typically uses a carriage return (CR, 0x0D in ASCII). In the Terminal on OS X though, pressing Return will generally send an LF.
Figuring out how to send a CR to the Terminal instead can be quite difficult, since searching for information on control characters, escape characters, the ASCII set, end of lines, CR's, LF's and CRLF's quickly becomes confusing! I hope this tip saves someone else the hours it took me to figure it out, because the solution is very simple.
To send an LF to the Terminal, press Return. You should get a new line, depending on the application you have running.
To send a CR to the Terminal, press Control-V, then Return. It should appear as ^M, depending on the application you have running. For example, when testing a proxy server I was working on, I used nc (netcat) to connect to it like so:
% nc 127.0.0.1 8080 GET /index.html HTTP/1.1^M ^MTo put the CRLF's on the end of each header, as required by the HTTP protocol, press Control-V, Return, Return. Of course, the ^M is not sent literally -- all the server will see is a CRLF. Too easy!