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

PR:		7828
Suggested by:	Daniel O'Connor <doconnor@gsoft.com.au>
Approved by:	sheldonh (mentor)
MFC after:	2 weeks
This commit is contained in:
Johan Karlsson 2002-07-23 00:42:56 +00:00
parent 61a875d706
commit 786c276fe4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=100538
4 changed files with 35 additions and 12 deletions

View File

@ -47,7 +47,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
.Op Fl f | i
.Op Fl f | i | n
.Op Fl pv
.Ar source_file target_file
.Nm
@ -55,7 +55,7 @@
.Fl R
.Op Fl H | Fl L | Fl P
.Oc
.Op Fl f | i
.Op Fl f | i | n
.Op Fl pv
.Ar source_file ... target_directory
.Sh DESCRIPTION
@ -121,6 +121,8 @@ regardless of its permissions.
.Fl f
option overrides any previous
.Fl i
or
.Fl n
options.)
.It Fl i
Cause
@ -136,6 +138,17 @@ the file copy is attempted.
.Fl i
option overrides any previous
.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.)
.It Fl p
Cause
@ -226,7 +239,9 @@ or fifo's.
.Pp
The
.Fl v
option is non-standard and its use in scripts is not recommended.
and
.Fl n
options are non-standard and their use in scripts is not recommended.
.Sh SEE ALSO
.Xr mv 1 ,
.Xr rcp 1 ,

View File

@ -86,8 +86,8 @@ static char emptystring[] = "";
PATH_T to = { to.p_path, emptystring, "" };
int iflag, pflag, fflag;
static int Rflag, rflag, vflag;
int fflag, iflag, nflag, pflag, vflag;
static int Rflag, rflag;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@ -103,7 +103,7 @@ main(int argc, char *argv[])
char *target;
Hflag = Lflag = Pflag = 0;
while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
while ((ch = getopt(argc, argv, "HLPRfinprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@ -122,11 +122,15 @@ main(int argc, char *argv[])
break;
case 'f':
fflag = 1;
iflag = 0;
iflag = nflag = 0;
break;
case 'i':
iflag = 1;
fflag = 0;
fflag = nflag = 0;
break;
case 'n':
nflag = 1;
fflag = iflag = 0;
break;
case 'p':
pflag = 1;

View File

@ -41,7 +41,7 @@ typedef struct {
} PATH_T;
extern PATH_T to;
extern int fflag, iflag, pflag;
extern int fflag, iflag, nflag, pflag, vflag;
__BEGIN_DECLS
int copy_fifo(struct stat *, int);

View File

@ -87,7 +87,11 @@ copy_file(FTSENT *entp, int dne)
*/
if (!dne) {
#define YESNO "(y/n [n]) "
if (iflag) {
if (nflag) {
if (vflag)
printf("%s not overwritten\n", to.p_path);
return (0);
} else if (iflag) {
(void)fprintf(stderr, "overwrite %s? %s",
to.p_path, YESNO);
checkch = ch = getchar();
@ -300,7 +304,7 @@ usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
"usage: cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target",
" cp [-R [-H | -L | -P]] [-f | -i] [-pv] src1 ... srcN directory");
"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target",
" cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory");
exit(EX_USAGE);
}