[Top][All Lists]

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

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

From: Stephane Chazelas
Subject: Re: [Help-bash] Using single quotes to escape a newline
Date: Thu, 2 Jul 2015 10:03:38 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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

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.

Something similar happens (in reverse) on the input side.

When you press Enter/Return, the terminal or terminal emulator
emits a CR character. That's translated to LF by the tty line
discipline (or readline in the case of bash). But again, that's
only for I/O to a terminal and is internal soup you should need
to worry about, the applications (the interpreter part of the
shell only sees LF characters).

When reading/writing to other types of files (like for shell
scripts, or output to a file), all there is is a LF character,
the line delimiter, a character special in the bash syntax.


reply via email to

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