Add the -n option, which automatically answers "no" to the overwrite question.

This commit is contained in:
David E. O'Brien 2002-03-22 07:45:36 +00:00
parent 98b28ee5b4
commit dce742c573
2 changed files with 27 additions and 6 deletions

View File

@ -43,7 +43,7 @@
.Nd move files .Nd move files
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl f | Fl i .Op Fl f | Fl i | Fl n
.Op Fl v .Op Fl v
.Ar source target .Ar source target
.Nm .Nm
@ -81,6 +81,8 @@ path.
.Fl f .Fl f
option overrides any previous option overrides any previous
.Fl i .Fl i
or
.Fl n
options.) options.)
.It Fl i .It Fl i
Cause Cause
@ -96,6 +98,17 @@ the move is attempted.
.Fl i .Fl i
option overrides any previous option overrides any previous
.Fl f .Fl f
or
.Fl n
options.)
.It Fl n
Do not overwriting an existing file.
(The
.Fl n
option overrides any previous
.Fl f
or
.Fl i
options.) options.)
.It Fl v .It Fl v
Cause Cause

View File

@ -68,7 +68,7 @@ static const char rcsid[] =
#include "pathnames.h" #include "pathnames.h"
int fflg, iflg, vflg; int fflg, iflg, nflg, vflg;
int copy(char *, char *); int copy(char *, char *);
int do_move(char *, char *); int do_move(char *, char *);
@ -85,15 +85,19 @@ main(int argc, char *argv[])
int ch; int ch;
char path[PATH_MAX]; char path[PATH_MAX];
while ((ch = getopt(argc, argv, "fiv")) != -1) while ((ch = getopt(argc, argv, "finv")) != -1)
switch (ch) { switch (ch) {
case 'i': case 'i':
iflg = 1; iflg = 1;
fflg = 0; fflg = nflg = 0;
break; break;
case 'f': case 'f':
fflg = 1; fflg = 1;
iflg = 0; iflg = nflg = 0;
break;
case 'n':
nflg = 1;
fflg = iflg = 0;
break; break;
case 'v': case 'v':
vflg = 1; vflg = 1;
@ -172,7 +176,11 @@ do_move(char *from, char *to)
#define YESNO "(y/n [n]) " #define YESNO "(y/n [n]) "
ask = 0; ask = 0;
if (iflg) { if (nflg) {
if (vflg)
printf("%s not overwritten\n", to);
return (0);
} else if (iflg) {
(void)fprintf(stderr, "overwrite %s? %s", to, YESNO); (void)fprintf(stderr, "overwrite %s? %s", to, YESNO);
ask = 1; ask = 1;
} else if (access(to, W_OK) && !stat(to, &sb)) { } else if (access(to, W_OK) && !stat(to, &sb)) {