# specify $fullpath in your original script # then source this one to get dir, filename and extension in separate variables dir=`dirname "$fullpath"` filename=`basename "$fullpath"` extension="${filename##*.}" filename="${filename%.*}"