xref: /titanic_44/usr/src/cmd/mvdir/mvdir.sh (revision 49b225e1cfa7bbf7738d4df0a03f18e3283426eb)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24#
25# Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
26# Use is subject to license terms.
27#
28
29#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
30#	  All Rights Reserved
31
32
33#ident	"%Z%%M%	%I%	%E% SMI"
34
35if [ $# != 2 ]
36then
37  echo "Usage: mvdir fromdir newname" >&2
38  exit 2
39fi
40if [ "$1" = . ]
41then
42	echo "mvdir: cannot move '.'" >&2
43	exit 2
44fi
45f=`basename "$1"`
46t="$2"
47if [ -d "$t" ]
48then
49	t="$t"/"$f"
50fi
51if [ -f "$t"  -o -d "$t" ]
52then
53  echo "$t" exists >&2
54  exit 1
55fi
56if [  ! -d "$1" ]
57then
58  echo "$1" must be a directory >&2
59  exit 1
60fi
61
62# *** common path tests: The full path name for $1 must not
63# *** 			 be an anchored substring of the full
64# ***			 path name for $2
65
66here=`pwd`
67cd "$1"
68from="`pwd`/"
69lfrom=`expr "$from" : "$from"`
70
71cd "$here"
72mkdir "$t"		# see if we can create the directory
73if [ $? != 0 ]
74then
75	exit
76fi
77cd "$t"
78to=`pwd`
79cd "$here"
80rmdir "$t"
81
82a=`expr "$to" : "$from"`
83if [ "$a" = "$lfrom" ]
84then
85  echo arguments have common path >&2
86  exit 1
87fi
88# ***
89
90mv "$1" "$t"
91