logo

utils-std

Collection of commonly available Unix tools
commit: 7f45e61983d77cadaaebadcfdfa2b924b9cfdf70
parent 46f972a09717e8184b6796370237b5425063e5f4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 26 Mar 2024 08:01:26 +0100

cmd/rm: When -f is passed, lack of operands isn't an error

Diffstat:

Mcmd/rm.c7+++++++
Mtest-cmd/rm.t7+++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/cmd/rm.c b/cmd/rm.c @@ -234,6 +234,13 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + if(argc == 0 && !force) + { + fprintf(stderr, "rm: missing operand\n"); + usage(); + return 1; + } + int err = 0; for(int i = 0; i < argc; i++) diff --git a/test-cmd/rm.t b/test-cmd/rm.t @@ -123,3 +123,10 @@ POSIX, -f shouldn't return an error when non-existant files are passed $ rm /var/empty/e/no/ent rm: Failed getting status for '/var/empty/e/no/ent': No such file or directory [1] + +POSIX, -f shouldn't return an error when no operands are passed + $ rm -f + $ rm + rm: missing operand + Usage: rm [-firRv] [files ...] + [1]