On 27/08/2024 08:39, Thomas Kimpton wrote:
"cp -n srcFile destFile" returns 0 if it copies the file. It also returns 0
if it fails to copy the file over an existing file. I would like "cp -n" to
return 1 (or perhaps EEXIST) when it will refuse to overwrite an existing
file. This would facilitate:

      cp -n srcFile destFile && chmod +x destFile

Or other similar idioms.

You're right that -n should have originally behaved like you suggest,
and indicate the failure to overwrite in the exit code.
However it's been in place so long, scripts have depended on the
existing behavior of exiting with success in this case.
We actually tried to make the change you suggested recently,
but there were issues for scripts so we reverted.

The next version of coreutils will have the --update=none-fail option
to behave as you expect.

cheers,
Pádraig

Reply via email to