home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / usr / bin / basename / basename~
Text File  |  1998-08-19  |  2KB  |  45 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    "@(#)basename:basename.sh    1.8.1.6"
  19. #ident  "$Header: basename.sh 1.2 91/06/26 $"
  20.  
  21. # ignore -- as first argument
  22. [ "$1" = -- ] && shift
  23.  
  24. if [ $# -gt 2 ]
  25. then
  26.     catalog=uxcore
  27.     label=UX:basename
  28.     /sbin/pfmt -l $label -g $catalog:1 "Incorrect usage\\n"
  29.     /sbin/pfmt -l $label -g $catalog:2 -s action "Usage: basename [ path [ suffix-pattern ] ]\\n"
  30.     exit 1
  31. fi
  32. #    If no first argument or first argument is null, make first argument
  33. #    "."  Add beginning slash, then remove trailing slashes, then remove 
  34. #    everything up through last slash, then remove suffix pattern if 
  35. #    second argument is present.
  36. #    If nothing is left, first argument must be of form //*, in which
  37. #     case the basename is /.
  38. exec /usr/bin/sed \
  39.     -e 's!/*$!!' \
  40.     -e 's!.*/!!' \
  41.     -e "s!\\(.\\)$2\$!\\1!" \
  42.     -e 's!^$!/!' <<!
  43. /${1:-.}
  44. !
  45.