I have a variable that contain a path like /home/test/file.jpg and I want to get only the filename out of the whole path, filename.jpg, any idea how to do that?
Below are ksh function replacements for basename and dirname:
# Using ksh pattern-matching operators, this function
# replaces the unix basename command. If a 2nd argument
# exists, strip off the extension.
function basename {
typeset v x
v=${1##*/}
x=${2#.} # get rid of the '.'
v=${v%.$x}
echo $v
}
# Using ksh pattern-matching operators, this function
# replaces the unix dirname command.
function dirname {
typeset v="$@"
echo ${v%/*}
}
# basename and dirname function examples
var=/usr/eds/ddir/ttest.c
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.