On 2026-11-16 15:53:51 +0100, Nicolas George wrote:
> Vincent Lefevre (HE12026-11-16):
> > I would have said that backslash + ASCII letter ([A-Za-z]) inside
> > double quotes is safe (probably with digits too) as used in many
> > scripts, and such characters are obviously not characters that need
> > escaping.
> 
> Why would it be OBVIOUS that the shell do not use the same escaping
> sequences as printf or the C language?

Contrary to the escape sequences in C, the purpose of backslash in a
shell is to "preserve the literal value of the following character".
Doing otherwise would be a source of confusion.

> > There are cases when one wants to be able to do expansion, knowing
> > that this is safe. For instance:
> 
> Yes, but what is your point?

Using single quotes is not possible in these cases.

$ printf "$?\n"
0

but

$ printf '$?\n'
$?

-- 
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)

Reply via email to