basename()

# basename() -- Returns filename component of path
# Usage: basename filename
#
# Example 1:
#
# echo $(basename "/usr/bin/chak");
#
# Example 2:
#
# string="$(basename "/usr/bin/chak.exe" ".exe")";
# echo $string;

basename() {
	local name="${1##*/}";
	local opt="$2";
	[ -n "$opt" ] && name="${name%.$opt}";
	echo "${name%$2}";
}

Leave a Reply

Your email address will not be published. Required fields are marked *