January 2001
Intermediate to advanced
480 pages
7h 22m
English
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
Read now
Unlock full access