3

The bash documentation says the following:

A non-quoted backslash ‘\’ is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of newline. If a \newline pair appears, and the backslash itself is not quoted, the \newline is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).

And the following:

The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified.

What is meant by "newline", is it the "n" character?

1

2 Answers 2

3

It refers to the literal newline character (LF, decimal no. 10 in ASCII), the one at the end of each and every line. The backslash creates continuation lines, as in this script:

#!/bin/sh
echo foo\
bar

The script contains echo foo\↵bar, which turns into echo foobar when the backslash-newline is removed. So it outputs foobar. (Try it.)

1
  • Not in all encoding is LF the last character of a line. It should be for UNIX of course.
    – user232326
    Commented Jan 25, 2018 at 23:15
1

What is meant by "newline", is it the "n" character?

No, it is not the n character. It is what printf prints in this command:

$ printf '\n'

It is as well the ASCII character number 10 (0a in hex) which is called "line feed (LF)" in ASCII lists

In fact, wikipedia has a whole page about it.

If you want to see a numeric value (in hex) both this commands will show it:

$ printf '\n' | od -tx1
0000000 0a
0000001

$ printf '\n' | xxd -p
0a

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .