On 2021/03/08 18:04, Paul Eggert wrote:
On 3/8/21 5:50 PM, L A Walsh wrote:
Data loss shown in original bug submission. As mentioned/documented
it was use of:
'touch -f <from filename> <destination filename>'
Sure, but what was the context of that command? Was it part of a shell
script? What was the script for? Can we see a copy? That sort of thing.
----
wasn't in a shell script.
Was interactive and thought '-f' was flag to take d+t from
the specified file. Instead, it lost the d+t on the file.
I probably could have restored from backup, but it was more annoying
than anything else, and didn't want to bother. Though I would have
preferred to have it work and not just silently consume the '-f'
switch and stomp over the 'from' file's d+t.
If it was in a script, it probably would have been debugged by now.
Didn't say it was "script-unfriendly".
On FreeBSD, touch's -f option is also a no-op, and I observe similar
behavior on Solaris 10 (where I lack the source code). So there are good
compatibility arguments for leaving things the way they are.
---
On any modern version of any of the unices that I've been
on that still exist, there is a fair chance that they would have
switched to '-r', though if unix versions you mention silently accept and
throw away a '-f' -- you can't necessarily know what their usage was, but
should have a record of why it was added in the gnu utils.
It seems odd to consume a switch where the meaning is not known for
specifically cases like this. I doubt it could be like 'date's
-f for a from file, as it seems like that would produce a date for
each line in the specified file, which would make no sense for touch.
All I know is I've been caught more than once by this, though I
usually remember there is something off about the touch command's options
and reread the man page before using it. But haven't always and not
sure I always remember either, which is why I would think that simply
ignoring it and not consuming a following arg or generating a warning:
Warning, '-f' assuming '-r' was intended
(if -f is followed by an existing filename)
if not, could just ignore it, but still might be ideal to
assume it was '-r', since if it is a non-existent filename,
it would warn of the command failing, like:
touch -f foo bar
/usr/bin/touch: Warning, '-f' assuming '-r' was intended
/usr/bin/touch: failed to get attributes of 'foo': No such file or directory