bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "touch -" touching standard output


From: Bob Proulx
Subject: Re: "touch -" touching standard output
Date: Mon, 26 Sep 2005 21:18:32 -0600
User-agent: Mutt/1.5.9i

Paul Eggert wrote:
> The recent changes involving adding better support for futimes,
> fchmod, and fchown got me to thinking that these system calls aren't
> easily accessible to shell scripts, which goes counter to a primary
> original motivation for the shell -- namely, that it was a thin shell
> around the operating system calls.

Seems reasonable.  I guess.  However, I personally don't think of the
shell as being a complete C programming layer and don't feel the need
to expose every library and system call to it.  But okay.  (I feel
that is more of the task of perl, python and ruby. :-)

> To help counteract this for futimes, we can have "touch -" touch the
> standard output, i.e., it can invoke futimes on the standard output
> rather than utimes on the file named "-".  This is pretty
> straightforward so I installed the following patch.

Making special cases such as "-" mean stdin or stdout always seemed
like an ugly hack to me.  It makes it more difficult to actually refer
to real files named "-".  My first memory of this is that 'tar' would
make use of that special name.  I don't know if that was the first use
or not but that was where I first ran into it.  I used that convention
in some of my own programs.  And later wished that I had not.  It is
really in-band control.  Which always has problems telling the data
from the control.

I would prefer if "-" were not special but that instead an option were
added such as --stdin and --stdout and those were used to access this
special mode.  This would be out-of-band control which avoids that
problem.

  touch --reference /tmp --stdin
  touch --date '1 hour ago' --stdout

That just seems to read better than:

  touch --reference /tmp -
  touch --date '1 hour ago' -

One disadvantage of the --stdin/--stdout method is that one can't use
a filename in a variable and have it select between.
  
  if [ $# -eq 0 ]; then
      filename=-
  else
      filename="$1"
  fi
  touch "$filename"

But I can't think of a case where that would be useful.  And I can't
think of how to handle it for the problem case where the filename
would be "-" either.

Note that I don't feel strongly about it because files named "-" are
unusual and unlikely to be a source of problems.  I just don't like
the special casing required which would not have been required
previously.  But it is certainly possible to contrive an example where
backward compatibility would be broken.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]