2016-11-07 15:57:25 +0000, Stephane Chazelas:
> 2016-11-07 15:40:15 +0000, Geoff Clare:
> [...]
> > > Same problem with "mv" (which I think would work just
> > > as well (with LC_ALL=C mv -i < /dev/null 2> /dev/null))
> > 
> > No, mv -i doesn't work just as well - it has a race condition.
> > If a file is created in between the existence check and the
> > rename() call, mv will remove the file.
> 
> How so? "mv -i" with /dev/null as stdin ("no" answer to prompt)
> is not supposed to remove anything.
[...]

However, at least with GNU mv, the exit code if the file exists
will be 0. So it can't be used here.

BTW, there's an issue in the spec for "mv":

> EXIT STATUS
>
>  The following exit values shall be returned:
>
>   0
>          All input files were moved successfully.
>  >0
>          An error occurred.

In

mv -i a b

if the user says "no", "a" will not be moved successfully, and
there will not have been any error.

Should probably be something like:

   0
          All input files (approved by the user with -i) were
          moved successfully.

Also, should failure to write the prompt or read the answer be
considered an error?

Using:

   mv -i a b  2>&- <&-

or

   mv -i a b < /dev/null 2>&-

seem to work with GNU or Solaris10 mv (in that it returns with
an error when a prompt fails to be issued) but not with
FreeBSD's

-- 
Stephane

Reply via email to