Subject: bug#21065: closed (Re: bug#21065: Small bug in touch)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 15 Jul 2015 16:37:02 +0000

Your bug report

#21065: Small bug in touch

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

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

Subject: Re: bug#21065: Small bug in touch
From: Eric Blake <[email-masked]>
To: Rickard Norlander <[email-masked]>, [email-masked]
Date: Wed, 15 Jul 2015 09:40:08 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

On 07/15/2015 09:31 AM, Eric Blake wrote:
> tag 21065 notabug
> thanks
> 
> On 07/15/2015 07:25 AM, Rickard Norlander wrote:
>> touch version 8.23
>>
>> Command:
>> $ touch -- '-'
>> Happens:
>> Returns successfully, but no file is created (if file exists, timestamp is
>> not updated)
> 
> Like many other tools, '-' is special-cased in touch to mean operation
> on stdin:

Looks like I'm not careful in what I wrote; most utilities treat '-' as
stdin, but touch documented...

> 
> $ touch --help | grep -A1 ' - '
> A FILE argument string of - is handled specially and causes touch to
> change the times of the file associated with standard output.

...that it was affecting stdout.

> 
> So you successfully touched stdin (in your case, /dev/tty).

Either way, in your example, since you were using an interactive shell,
/dev/tty was still touched,

>  If you want
> to create a file named '-', use 'touch ./-'.

and this advice still holds.

On a related note, the just-released 8.24 fixed 'tee -' to NOT treat '-'
as meaning stdout (which was a violation of POSIX) and to instead treat
it as a literal file.

Here's what POSIX says:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Guideline 13:
    For utilities that use operands to represent files to be opened for
either reading or writing, the '-' operand should be used to mean only
standard input (or standard output when it is clear from context that an
output file is being specified) or a file named -.

It's not obvious whether 'touch' is opening a file for reading or
writing (it doesn't always have to open a file, after all, but if it
creates the file it IS opening it even if it doesn't read or write to
the file).

We changed 'touch -' way back in 5.90, in 2005, when making a bunch of
POSIX cleanups, so I guess the argument at the time probably still holds
that we are not in violation of that guideline by treating '-' as
stdout, even though POSIX does not explicitly describe that behavior in:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

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

Subject: Small bug in touch
From: Rickard Norlander <[email-masked]>
To: [email-masked]
Date: Wed, 15 Jul 2015 15:25:02 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

touch version 8.23

Command:
$ touch -- '-'
Happens:
Returns successfully, but no file is created (if file exists, timestamp is
not updated)

Rickard