From 57cf2a735a11f5e307cb7be92bc012d54158bdf4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 17 Mar 2022 15:17:44 -0400 Subject: [PATCH] add support for '-f' option to shell rm built-in command --- doc/src/shell.rst | 3 ++- src/input.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/src/shell.rst b/doc/src/shell.rst index 19a8e1afe3..6ebd9e2abf 100644 --- a/doc/src/shell.rst +++ b/doc/src/shell.rst @@ -21,7 +21,8 @@ Syntax *mv* args = old new old = old filename new = new filename or destination folder - *rm* args = file1 file2 ... + *rm* args = [-f] file1 file2 ... + -f = turn off warnings (optional) file1,file2 = one or more filenames to delete *rmdir* args = dir1 dir2 ... dir1,dir2 = one or more directories to delete diff --git a/src/input.cpp b/src/input.cpp index c504210211..689c016b68 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1218,10 +1218,17 @@ void Input::shell() } else if (strcmp(arg[0],"rm") == 0) { if (narg < 2) error->all(FLERR,"Illegal shell rm command"); if (me == 0) { - for (int i = 1; i < narg; i++) { + int i = 1; + bool warn = true; + if (strcmp(arg[i], "-f") == 0) { + warn = false; + ++i; + } + for (;i < narg; i++) { if (platform::unlink(arg[i]) < 0) - error->warning(FLERR, "Shell command 'rm {}' failed with error '{}'", - arg[i], utils::getsyserror()); + if (warn) + error->warning(FLERR, "Shell command 'rm {}' failed with error '{}'", + arg[i], utils::getsyserror()); } } } else if (strcmp(arg[0],"rmdir") == 0) {