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 argumentsif (($# == 0 || $# > 2))thenprint "Usage: $0 string [suffix]"exit 1fi# Get the basenameBASE=${1##*/}# See if suffix arg was givenif (($# > 1))then# Display basename without suffixprint ${BASE%$2}else# Display basenameprint $BASEfi