Basename - kbasename

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Appendix D.  Sample Korn Shell Scripts


Basename - kbasename

This is the Korn shell version of the Unix basename command. It is used to return the last part of a pathname. A suffix can also be given to be stripped from the resulting base directory. The substring feature is used to get the basename and strip off the suffix.

 #!/bin/ksh  #  #     kbasename - Korn shell basename  #  # Check arguments  if (($# == 0 || $# > 2))  then        print "Usage: $0 string [suffix]"        exit 1  fi  # Get the basename  BASE=${1##*/}  # See if suffix arg was given  if (($# > 1))  then        # Display basename without suffix        print ${BASE%$2}  else        # Display basename        print $BASE  fi 

       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net