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, 1 Jul 2015 17:52:11 -0700

>
> Where that book is incorrect is about the backslash case.
>

> In:
>
> ​​
> echo 'x
> y'
>
> The *special meaning of* newline is removed in that the newline
> is passed to echo as any other non-special character while in
>
> ​​
> echo x
> y
>
> The newline would be considered as a command delimiter (["echo",
> "x"] command followed by ["y"] command).
>
> In
>
> echo x\
> y
>
> however, the newline (and backslash) is removed altogether. It's
> the same as
>
> echo xy
>
>
​Sephane, that is very helpful, thank you. So, there are really three cases
here:

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).


reply via email to

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