dirname()

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

dirname() {
	local dir="${1%${1##*/}}";
	[ "${dir:=./}" != "/" ] && dir="${dir%?}";
	echo "$dir";
}