GNU bug report logs - #45700
rm should not prompt if ! isatty(2)

Previous Next

Package: coreutils;

Reported by: John Wiersba <jrw32982 <at> yahoo.com>

Date: Wed, 6 Jan 2021 18:57:01 UTC

Severity: normal

Tags: notabug

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45700 in the body.
You can then email your comments to 45700 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#45700; Package coreutils. (Wed, 06 Jan 2021 18:57:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to John Wiersba <jrw32982 <at> yahoo.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 06 Jan 2021 18:57:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: John Wiersba <jrw32982 <at> yahoo.com>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: rm should not prompt if ! isatty(2)
Date: Wed, 6 Jan 2021 18:56:02 +0000 (UTC)
[Message part 1 (text/plain, inline)]
$ /bin/rm --version
rm (GNU coreutils) 8.30

$ uname -a
Linux xxx 5.4.0-59-generic #65-Ubuntu SMP Thu Dec 10 12:01:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID:    Linuxmint
Description:    Linux Mint 20
Release:    20
Codename:    ulyana

$ touch asdf && chmod a-w asdf && rm asdf 2>&1 | catrm: remove write-protected regular empty file 'asdf'?          # should *not* prompt

If the prompt cannot be seen, then it can't be properly answered, so there is no point in prompting and consequently leaving the user with a hanging command and no way to know what's being expected of them.  Instead rm should attempt to remove the file and succeed or fail based on the result.  Same for any other commands (mv, cp) in similar situations.

I know about the options -f and --interactive=never, but they shouldn't be needed in this case.

Thanks!
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#45700; Package coreutils. (Wed, 06 Jan 2021 19:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 45700 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: John Wiersba <jrw32982 <at> yahoo.com>
Cc: 45700 <at> debbugs.gnu.org
Subject: Re: bug#45700: rm should not prompt if ! isatty(2)
Date: Wed, 6 Jan 2021 11:16:57 -0800
On 1/6/21 10:56 AM, John Wiersba via GNU coreutils Bug Reports wrote:
> $ touch asdf && chmod a-w asdf && rm asdf 2>&1 | catrm: remove write-protected regular empty file 'asdf'?          # should*not*  prompt
> 
> If the prompt cannot be seen, then it can't be properly answered, so there is no point in prompting and consequently leaving the user with a hanging command and no way to know what's being expected of them.  Instead rm should attempt to remove the file and succeed or fail based on the result.

POSIX requires the current behavior; see clause 3 in:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html

Although GNU rm needn't follow POSIX blindly, it's doubtful that rm 
should remove the file in this particular case, as the longstanding 
tradition is that plain "rm" does not remove unwriteable files without 
more confirmation.

Since you know about "rm -f" I suggest using that (that's what everyone 
else does...).




Information forwarded to bug-coreutils <at> gnu.org:
bug#45700; Package coreutils. (Wed, 06 Jan 2021 20:33:02 GMT) Full text and rfc822 format available.

Message #11 received at 45700 <at> debbugs.gnu.org (full text, mbox):

From: John Wiersba <jrw32982 <at> yahoo.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: "45700 <at> debbugs.gnu.org" <45700 <at> debbugs.gnu.org>
Subject: Re: bug#45700: rm should not prompt if ! isatty(2)
Date: Wed, 6 Jan 2021 20:31:47 +0000 (UTC)
[Message part 1 (text/plain, inline)]
 Thanks for your reply, Paul!
I see what you're talking about; thanks for the link.  The POSIX spec seems broken in that regard.  I guess I'm going to be adding -f to my scripts!  (I was surprised to see my script hang today for this very reason).  

Maybe something could be added to the FAQ or the manpage?  I didn't see anything documented about prompting for an unwritable file.  Although I'd seen those prompts before, I was surprised to find that prompting happens even when stdout is not a tty.  Something like this maybe:


Per the POSIX spec, rm will prompt to stderr before removing an unwritable file, even if stderr is not a tty.

Another possibility is to add a timeout on the prompt when writing a prompt to a non-tty (with an inferred reply of "no").
-- John

    On Wednesday, January 6, 2021, 2:17:00 PM EST, Paul Eggert <eggert <at> cs.ucla.edu> wrote:  
 
 On 1/6/21 10:56 AM, John Wiersba via GNU coreutils Bug Reports wrote:
> $ touch asdf && chmod a-w asdf && rm asdf 2>&1 | catrm: remove write-protected regular empty file 'asdf'?          # should*not*  prompt
> 
> If the prompt cannot be seen, then it can't be properly answered, so there is no point in prompting and consequently leaving the user with a hanging command and no way to know what's being expected of them.  Instead rm should attempt to remove the file and succeed or fail based on the result.

POSIX requires the current behavior; see clause 3 in:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html

Although GNU rm needn't follow POSIX blindly, it's doubtful that rm 
should remove the file in this particular case, as the longstanding 
tradition is that plain "rm" does not remove unwriteable files without 
more confirmation.

Since you know about "rm -f" I suggest using that (that's what everyone 
else does...).  
[Message part 2 (text/html, inline)]

Added tag(s) notabug. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 21 Feb 2022 10:08:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 45700 <at> debbugs.gnu.org and John Wiersba <jrw32982 <at> yahoo.com> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 21 Feb 2022 10:08:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 21 Mar 2022 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 35 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.