[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "touch -" touching standard output
From: |
Paul Eggert |
Subject: |
Re: "touch -" touching standard output |
Date: |
Mon, 26 Sep 2005 11:24:50 -0700 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Eric Blake <address@hidden> writes:
> According to Paul Eggert on 9/25/2005 12:21 AM:
>> we can have "touch -" touch the standard output...
>
> Does this countradict POSIX,
Not as far as I can see. Admittedly this is a confusing area.
Here's the argument. POSIX 1003.1 section 12.2
<http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html#tag_12_02>
says this:
Guideline 13: For utilities that use operands to represent files to
be opened for either reading or writing, the '-' operand should be
used only to mean standard input (or standard output when it is
clear from context that an output file is being specified).
This provision arguably applies to "touch", since "touch FILE" opens
FILE for writing if FILE does not exist.
The counterargument would be, though, that standard output does exist
in the case where "touch -" is useful, and "touch FILE" does not open
FILE for writing if FILE exists, so Guideline 13 does not apply here.
However, even if one concedes this counterargument, one is left with
the conclusion that POSIX does not prohibit "touch -" from affecting
standard output, since Guideline 13 is silent about what "-" means in
a file name context when the file is not opened for either reading or
writing. Hence an implementation is allowed to define "touch -" to
touch standard output.
A similar argument would conclude that "chmod 644 -" and "chown root
-" can affect standard output, if the implementation so chooses.
(I haven't implemented that yet, though.)
> Also, it seems a bit strange that - maps to stdout, when it usually
> maps to stdin.
One usually thinks of "touch FILE" as writing to FILE. Historically
that's how "touch" actually worked in all cases, though nowadays a
utime-like function is used when FILE exists. So it's somewhat more
natural to map it to standard output. There is some precedent for
this, e.g., "tee -".
PS. I should mention that "touch -" was a way-past-the-last-minute
change and might be withdrawn before the next release -- I'm afraid I
overstepped the bounds on the schedule. I'm still waiting for Jim's
word on whether to withdraw it, at least for now.