option -f and -i are exclusive
all flag variables initialized with zero respond `Y' is equal to `y' update usage string prompt only if source exist ignore -i option if file descriptor stdin not refers to a valid terminal type device
This commit is contained in:
parent
ef83c41f6d
commit
1efb053dc4
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.2 1994/09/24 02:56:06 davidg Exp $
|
||||
.\" $Id: mv.1,v 1.3 1995/08/15 19:44:39 joerg 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
|
||||
|
21
bin/mv/mv.c
21
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.2 1994/09/24 02:56:07 davidg Exp $
|
||||
* $Id: mv.c,v 1.3 1995/10/07 10:42:48 bde Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@ -79,13 +79,17 @@ main(argc, argv)
|
||||
int ch;
|
||||
char path[MAXPATHLEN + 1];
|
||||
|
||||
while ((ch = getopt(argc, argv, "-if")) != EOF)
|
||||
fflg = iflg = 0;
|
||||
|
||||
while ((ch = getopt(argc, argv, "-if?")) != EOF)
|
||||
switch (ch) {
|
||||
case 'i':
|
||||
iflg = 1;
|
||||
iflg = isatty(STDIN_FILENO);
|
||||
fflg = 0;
|
||||
break;
|
||||
case 'f':
|
||||
fflg = 1;
|
||||
iflg = 0;
|
||||
break;
|
||||
case '-': /* Undocumented; for compatibility. */
|
||||
goto endarg;
|
||||
@ -152,6 +156,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);
|
||||
@ -167,7 +178,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);
|
||||
}
|
||||
}
|
||||
@ -303,6 +314,6 @@ void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: mv [-if] src target;\n or: mv [-if] src1 ... srcN directory\n");
|
||||
"usage: mv [-if] src target;\n or: mv [-i | -f] src1 ... srcN directory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user