Merge commit '00f1a4f432b3d8aad1aa270e91c44c57f03ef407'
[unleashed.git] / usr / src / cmd / mvdir / mvdir.sh
blob980a9722fae1c35fadfcce13f8471c1b459886ea
1 #!/sbin/sh
3 # CDDL HEADER START
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.
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.
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]
21 # CDDL HEADER END
25 # Copyright 1997 Sun Microsystems, Inc. All rights reserved.
26 # Use is subject to license terms.
29 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
30 # All Rights Reserved
33 #ident "%Z%%M% %I% %E% SMI"
35 if [ $# != 2 ]
36 then
37 echo "Usage: mvdir fromdir newname" >&2
38 exit 2
40 if [ "$1" = . ]
41 then
42 echo "mvdir: cannot move '.'" >&2
43 exit 2
45 f=`basename "$1"`
46 t="$2"
47 if [ -d "$t" ]
48 then
49 t="$t"/"$f"
51 if [ -f "$t" -o -d "$t" ]
52 then
53 echo "$t" exists >&2
54 exit 1
56 if [ ! -d "$1" ]
57 then
58 echo "$1" must be a directory >&2
59 exit 1
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
66 here=`pwd`
67 cd "$1"
68 from="`pwd`/"
69 lfrom=`expr "$from" : "$from"`
71 cd "$here"
72 mkdir "$t" # see if we can create the directory
73 if [ $? != 0 ]
74 then
75 exit
77 cd "$t"
78 to=`pwd`
79 cd "$here"
80 rmdir "$t"
82 a=`expr "$to" : "$from"`
83 if [ "$a" = "$lfrom" ]
84 then
85 echo arguments have common path >&2
86 exit 1
88 # ***
90 mv "$1" "$t"