help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Using single quotes to escape a newline


From: Michael Convey
Subject: Re: [Help-bash] Using single quotes to escape a newline
Date: Wed, 29 Jul 2015 17:28:56 -0700

On Thu, Jul 2, 2015 at 2:03 AM, Stephane Chazelas <
address@hidden> wrote:

> 2015-07-01 17:52:11 -0700, Michael Convey:
> [...]
> > 1) Unescaped: \n = command delimiter (and carriage return)
> > 2) Escaped with \: \ and \n are discarded
> > 3) Escaped with ' ' or " ": \n loses its special property in bash
> (command
> > delimiter) and it is handed off to the command, which interprets it
> > according to its programming (in the case of echo, as a carriage return).
>
> echo doesn't interpret the newline/linefeed character. That
> character is not special in any way for echo. It just writes it
> on its stdout like any other non-special character. The only
> special character for echo (some echos) is backslash.
>
> When stdout is a terminal device, that's the same except that
> the tty line discipline of that device (a software module in the
> kernel pushed on top of a serial or pty device) will typically
> convert it to \r\n before it's  sent over the wire to the
> terminal (or made available for reading on the master side of
> the pseudo-terminal in the case of a terminal emulator like
> xterm). That's controlled by the onlcr stty setting.
>
> That's just a technicality of the terminal processing. For
> terminals, the CR and LF characters are control characters: CR
> moves the cursor to the first column and LF moves the cursor
> down.
>
> The LF character is the text line delimiter on Unix, so for
> lines to be displayed properly on a terminal, that translation
> has to occur.
>
>

​
Are you saying that when echo sends its output to stdout, and only when
stdout is the terminal, the kernel converts the <newline> to \r\n? In \r\n
does \r = <CR> (carriage return) and \n = <newline>​?
 In this case, is \n interpreted as <LF> (line feed)?
​


reply via email to

[Prev in Thread] Current Thread [Next in Thread]