home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / usr / bin / dirname / dirname~
Text File  |  1998-08-19  |  2KB  |  51 lines

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #    Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  12. #      All Rights Reserved
  13.  
  14. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  15. #    The copyright notice above does not evidence any
  16. #    actual or intended publication of such source code.
  17.  
  18. #ident    "@(#)dirname:dirname.sh    1.6.1.4"
  19. #ident "$Header: /sms/sinixV5.4es/rcs/s19-full/usr/src/cmd/dirname/dirname.sh,v 1.1 91/02/28 16:55:26 ccs Exp $"
  20.  
  21. # ignore -- as first argument
  22. [ "$1" = -- ] && shift
  23.  
  24. if [ $# -gt 1 ]
  25. then
  26.     catalog=uxcore
  27.     label=UX:dirname
  28.     /sbin/pfmt -l $label -g $catalog:1 "Incorrect usage\\n"
  29.     /sbin/pfmt -l $label -g $catalog:3 -s action "Usage: dirname [ path ]\\n"
  30.     exit 1
  31. fi
  32. #    First check for pathnames of form //*non-slash*/* in which case the 
  33. #    dirname is /.
  34. #    Otherwise, remove the last component in the pathname and slashes 
  35. #    that come before it.
  36. #    If nothing is left, dirname is "."
  37. ans=`/usr/bin/expr \
  38.     "${1:-.}/" : '\(/\)/*[^/]*//*$' `
  39. if [ -n "$ans" ];then
  40.     echo $ans
  41. else
  42.     ans=`/usr/bin/expr \
  43.         "${1:-.}/" : '\(.*[^/]\)//*[^/][^/]*//*$' `
  44.     if [ -n "$ans" ];then
  45.         echo $ans
  46.     else
  47.         echo "."
  48.     fi
  49. fi
  50. exit 0
  51.