please explain the difference between Carriage return (`r) and New line (`n) in powershell

Can someone please explain the difference between Carriage return (`r) and New line (`n) in powershell.
LVL 3
Gopi RajuSystem AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alex Green3rd Line Server SupportCommented:
The /r stands for "return" or "carriage return" which owes it's history to the typewriter. A carriage return moved your carriage all the way to the right so you were typing at the start of the line. The /n stands for "new line", again, from typewriter days you moved down to a new line.

I did just pull that from google, pretty sure it's right :D
0
ste5anSenior DeveloperCommented:
They are two different non-printable characters in the ASCII table... usually used as text line terminator. The names come from the type write as already explained.

And because printers and modern computers are no type writers, we have a slight disagreement in the community, what the correct text line terminator should be:

CR LF is used by Windows, thus the original typewriter sequence to get the first position in the new line.
LF is used by Unix-style OS and MacOs.

Rumors tell that the LF was used to save a byte back in those days.

btw, LF is 0xA0 (10d) and CR is 0xC0 (13d)
4
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
When I was studying 9th standard learned type writing (without using computer keyboard)
Steps followed using that typewriter:
type following characters (without space)
a
s
d
f
g
f
;
l
k
j
h
j
There was no Enter key in that typewriter.
it was required to move the carriage to the beginning of the line (\r)
and rotate that carriage one time(\n) to go the new line.

This is what is happening if you use C:\Windows\System32\notepad.exe
Typing following characters
Testing Press Enter
Save and close notepad.exe
Internally this is saved as:
Sample output of that file:
$ /bin/cat 29108662.txt
testing

Open in new window


$ /usr/bin/file  29108662.txt
29108662.txt: ASCII text, with CRLF line terminators

Open in new window


$ /usr/bin/od -bc  29108662.txt
0000000 164 145 163 164 151 156 147 015 012
          t   e   s   t   i   n   g  \r  \n
0000011

Open in new window

0000000 being offset (octal) value
At position zero t
position 1 e
position 2 s
position 3 t
position 4 i
position 5 n
position 6 g
position 7 \r
position 8 \n
No character at position 9
Octal value of 9 is 11 => 0000011

This is how it is happening when using CRLF (carriage return and line feed)
at Linux oriented operating systems.
$ echo "AIX CYGWIN_NT HP-UX Linux Linux UNIX powershell" | /usr/bin/tr " " "\n" | /bin/sort -u
AIX
CYGWIN_NT
HP-UX
Linux
UNIX
powershell

Open in new window

new lines used to be written without carriage return(\r)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.