[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#21065: Small bug in touch
From: |
Eric Blake |
Subject: |
bug#21065: Small bug in touch |
Date: |
Wed, 15 Jul 2015 10:36:56 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 |
[resending without a signature - I didn't see my reply land at
http://debbugs.gnu.org/21065, so I wonder if the list filters are
accidentally eating GPG-signed mail again]
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