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
Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.