option -f and -i are exclusive (Posix)
respond `Y' is equal to `y' update usage string prompt only if source exist
This commit is contained in:
parent
a03bf4ac6a
commit
5fd463ac12
19
bin/mv/mv.1
19
bin/mv/mv.1
@ -33,7 +33,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)mv.1 8.1 (Berkeley) 5/31/93
|
||||
.\" $Id: mv.1,v 1.3 1995/08/15 19:44:39 joerg Exp $
|
||||
.\" $Id: mv.1,v 1.4 1996/02/18 18:44:56 wosch Exp $
|
||||
.\"
|
||||
.Dd May 31, 1993
|
||||
.Dt MV 1
|
||||
@ -77,17 +77,25 @@ The following options are available:
|
||||
Do not prompt for confirmation before overwriting the destination
|
||||
path.
|
||||
(The
|
||||
.Fl i
|
||||
option is ignored if the
|
||||
.Fl f
|
||||
option is specified.)
|
||||
option overrides any previous
|
||||
.Fl i
|
||||
options.)
|
||||
.It Fl i
|
||||
Causes
|
||||
.Nm mv
|
||||
to write a prompt to standard error before moving a file that would
|
||||
overwrite an existing file.
|
||||
If the response from the standard input begins with the character ``y'',
|
||||
If the response from the standard input begins with the character
|
||||
.Sq Li y
|
||||
or
|
||||
.Sq Li Y ,
|
||||
the move is attempted.
|
||||
(The
|
||||
.Fl i
|
||||
option overrides any previous
|
||||
.Fl f
|
||||
options.)
|
||||
.El
|
||||
.Pp
|
||||
It is an error for either the
|
||||
@ -121,6 +129,7 @@ The
|
||||
utility exits 0 on success, and >0 if an error occurs.
|
||||
.Sh SEE ALSO
|
||||
.Xr cp 1 ,
|
||||
.Xr rm 1 ,
|
||||
.Xr symlink 7
|
||||
.Sh STANDARDS
|
||||
The
|
||||
|
19
bin/mv/mv.c
19
bin/mv/mv.c
@ -33,7 +33,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: mv.c,v 1.5 1996/02/19 00:44:19 wosch Exp $
|
||||
* $Id: mv.c,v 1.6 1996/02/19 05:51:13 pst Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@ -83,9 +83,11 @@ main(argc, argv)
|
||||
switch (ch) {
|
||||
case 'i':
|
||||
iflg = 1;
|
||||
fflg = 0;
|
||||
break;
|
||||
case 'f':
|
||||
fflg = 1;
|
||||
iflg = 0;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
@ -149,6 +151,13 @@ do_move(from, to)
|
||||
* make sure the user wants to clobber it.
|
||||
*/
|
||||
if (!fflg && !access(to, F_OK)) {
|
||||
|
||||
/* prompt only if source exist */
|
||||
if (lstat(from, &sb) == -1) {
|
||||
warn("%s", from);
|
||||
return (1);
|
||||
}
|
||||
|
||||
ask = 0;
|
||||
if (iflg) {
|
||||
(void)fprintf(stderr, "overwrite %s? ", to);
|
||||
@ -164,7 +173,7 @@ do_move(from, to)
|
||||
if (ask) {
|
||||
if ((ch = getchar()) != EOF && ch != '\n')
|
||||
while (getchar() != '\n');
|
||||
if (ch != 'y')
|
||||
if (ch != 'y' && ch != 'Y')
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
@ -299,7 +308,9 @@ copy(from, to)
|
||||
void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: mv [-if] src target;\n or: mv [-if] src1 ... srcN directory\n");
|
||||
(void)fprintf(stderr,
|
||||
"\
|
||||
usage: mv [-i | -f] src target;\n\
|
||||
or: mv [-i | -f] src1 ... srcN directory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user