Subject: bug#14299: closed (Re: bug#14299: Incorrect output of `printf "\\n"`)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 29 Apr 2013 15:43:03 +0000

Your bug report

#14299: Incorrect output of  `printf "\\n"`

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
14299: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14299
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#14299: Incorrect output of `printf "\\n"`
From: Eric Blake <[email-masked]>
To: Pavel Elkind <[email-masked]>
Cc: [email-masked]
Date: Mon, 29 Apr 2013 09:42:00 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 14299 notabug
thanks

On 04/28/2013 12:44 PM, Pavel Elkind wrote:
> Dear developers,
> 
> I found the following potential bug in printf (version 8.17).
> 
> Actual result: 
> `printf "\\n"` prints a newline caracter.

Of course.  That's what POSIX requires it to print.

$ set -x
$ printf ".\\n."
+ printf '.\n.'
.
.
$ set -

> 
> Expected result:
> `printf "\\n"` prints a sequence of two individual characters, '\' and 'n', like '\n',  but  not a newline character.

If you want printf to print a literal backslash, you have to properly
escape it.  There are two levels of escaping to consider; shell escaping
(before printf ever sees its argv), and printf escaping.  You missed a
level, because you forgot that within "", the shell converts \\ into a
literal \ as part of the argv, and as my 'set -x' trace showed above,
you were passing only one backslash, not two, to printf.  Within printf,
when it sees the single backslash-n sequence, it converts that escape
sequence to newline.

You probably meant to do any one of these equivalent actions:

printf '.\\n.'
printf .\\\\n.
printf ".\\\\n."

all of which result in the argv handed to printf still containing two
backslashes.

As such, I'm closing this as not a bug, although you may continue to
reply here if you have further comments.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Subject: Incorrect output of `printf "\\n"`
From: Pavel Elkind <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Sun, 28 Apr 2013 18:44:23 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Dear developers,

I found the following potential bug in printf (version 8.17).

Actual result: 
`printf "\\n"` prints a newline caracter.

Expected result:
`printf "\\n"` prints a sequence of two individual characters, '\' and 'n', like '\n',  but  not a newline character.

Please address the above issue,

Many thanks,
Pavel