home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 11.ddi / usr / sbin / mvdir < prev   
Encoding:
Text File  |  1990-12-08  |  1.3 KB  |  78 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12. #ident    "@(#)/usr/sbin/mvdir.sl 1.1 4.0 12/08/90 21083 AT&T-USL"
  13. if [ $# != 2 ]
  14. then
  15.   echo "Usage: mvdir fromdir newname" >&2
  16.   exit 2
  17. fi
  18. if [ $1 = . ]
  19. then
  20.     echo "mvdir: cannot move '.'" >&2
  21.     exit 2
  22. fi
  23. f=`basename $1`
  24. t=$2
  25. if [ -d $t ]
  26. then
  27.     t=$t/$f
  28. fi
  29. if [ -f $t  -o -d $t ]
  30. then
  31.   echo $t exists >&2
  32.   exit 1
  33. fi
  34. if [  ! -d $1 ]
  35. then
  36.   echo $1 must be a directory >&2
  37.   exit 1
  38. fi
  39.  
  40. # *** common path tests: The full path name for $1 must not
  41. # ***              be an anchored substring of the full
  42. # ***             path name for $2
  43.  
  44. here=`pwd`
  45. cd $1
  46. from=`pwd`
  47. lfrom=`expr $from : $from`
  48.  
  49. cd $here
  50. mkdir $t        # see if we can create the directory
  51. if [ $? != 0 ]
  52. then
  53.     exit
  54. fi
  55. cd $t
  56. to=`pwd`
  57. cd $here
  58. rmdir $t
  59.  
  60. a=`expr $to : $from`
  61. if [ $a = $lfrom ]
  62. then
  63.   echo arguments have common path >&2
  64.   exit 1
  65. fi
  66. # ***
  67.  
  68. T=`expr $t : '\(.*\)/' \| .`
  69. if /usr/sbin/link $1 $t ; then
  70.     :
  71. else
  72.     echo "Cannot link to" $t >&2
  73.     exit 2
  74. fi
  75. /usr/sbin/unlink $1
  76. /usr/sbin/unlink $t/..
  77. /usr/sbin/link $T $t/..
  78.