home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 5.ddi / usr / bin / dirname < prev   
Encoding:
Text File  |  1990-12-08  |  792 b   |  27 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/bin/dirname.sl 1.1 4.0 12/08/90 50689 AT&T-USL"
  13. if [ $# -gt 1 ]
  14. then
  15.     echo >&2 "Usage: dirname [ path ]"
  16.     exit 1
  17. fi
  18. #    First check for pathnames of form //*non-slash*/* in which case the 
  19. #    dirname is /.
  20. #    Otherwise, remove the last component in the pathname and slashes 
  21. #    that come before it.
  22. #    If nothing is left, dirname is "."
  23. exec /usr/bin/expr \
  24.     "${1:-.}/" : '\(/\)/*[^/]*//*$'  \| \
  25.     "${1:-.}/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
  26.     .
  27.