Posix rm 1(a):

> If the -f option is not specified, rm shall write a diagnostic message to 
> standard error.
> Go on to any remaining files.

Want:

# rm x
rm: x: No such file or directory

Have, calling from script:

# rm x
rm ro x (y/N):

Attaching patch, but having deja vu as though toy rm did behave like posix
while I was scripting earlier this year and there was some discussion here.
From 02c69847dee7543908f0928d9b170a8f0190c384 Mon Sep 17 00:00:00 2001
From: Denys Nykula <[email protected]>
Date: Tue, 12 Nov 2019 16:55:35 +0000
Subject: [PATCH] Don't rm prompt for nonexistent, just warn.

---
 tests/rm.test   | 2 ++
 toys/posix/rm.c | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/tests/rm.test b/tests/rm.test
index 9f2b801..ab6a97d 100755
--- a/tests/rm.test
+++ b/tests/rm.test
@@ -11,6 +11,8 @@ echo "abcdefghijklmnopqrstuvwxyz" > file.txt
 testing "text-file" "rm file.txt && [ ! -e file.txt ] && echo 'yes'" "yes\n" "" ""
 rm -f file*
 
+testing "-i nonexistent" "</dev/zero rm -i file.txt 2>/dev/null || echo 'yes'" "yes\n" "" ""
+
 mkdir dir
 testing "empty directory" "rm -r dir && [ ! -d dir ] && echo 'yes'" "yes\n" "" ""
 rm -rf dir
diff --git a/toys/posix/rm.c b/toys/posix/rm.c
index 8874b54..2a6bc28 100644
--- a/toys/posix/rm.c
+++ b/toys/posix/rm.c
@@ -37,6 +37,10 @@ static int do_rm(struct dirtree *try)
   // This is either the posix section 2(b) prompt or the section 3 prompt.
   if (!FLAG(f)
     && (!S_ISLNK(try->st.st_mode) && faccessat(fd, try->name, W_OK, 0))) or++;
+
+  // Posix section 1(a), don't prompt for nonexistent.
+  if (or && errno == ENOENT) goto skip;
+
   if (!(dir && try->again) && ((or && isatty(0)) || FLAG(i))) {
     char *s = dirtree_path(try, 0);
 
-- 
2.24.0

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to