home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 5.ddi / usr / bin / basename < prev    next >
Encoding:
Text File  |  1990-12-08  |  992 b   |  28 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/basename.sl 1.1 4.0 12/08/90 48390 AT&T-USL"
  13. if [ $# -gt 2 ]
  14. then
  15.     echo >&2 "Usage:  basename [ path [ suffix-pattern ] ]"
  16.     exit 1
  17. fi
  18. #    If no first argument or first argument is null, make first argument
  19. #    "."  Add beginning slash, then remove trailing slashes, then remove 
  20. #    everything up through last slash, then remove suffix pattern if 
  21. #    second argument is present.
  22. #    If nothing is left, first argument must be of form //*, in which
  23. #     case the basename is /.
  24. exec /usr/bin/expr \
  25.     "/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)' : "\\(.*\\)$2\$"  \|  \
  26.     "/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)'    \|  \
  27.     "/${1:-.}" : '.*/\(..*\)' 
  28.