[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: basename, dirname why not built-in?
|
From: |
Chris F.A. Johnson |
|
Subject: |
Re: basename, dirname why not built-in? |
|
Date: |
Wed, 13 Feb 2002 21:12:13 GMT |
On 13 Feb 2002, Dan Jacobson wrote:
> $ type basename
> basename is /bin/basename
>
> OK, but I've seen a lost of built-ins that do more than basename...
> So how can one justify having built-ins for some of the simple stuff
> in /bin but not all of them? Got to make a definition of where to
> draw the line. Lots of them or none of them.
>
> $ type dirname
> dirname is /usr/bin/dirname
>
> Isn't that one just child's play to implement... wouldn't there be no
> better a justification for a built-in than dirname? [save lots of CPU
> time per call.]
basename ()
{
local path=$1;
local suffix=$2;
case "$path" in
*/ | "") basename ${path%/} $suffix ;;
*) path=${path##*/};
echo ${path%$suffix}
;;
esac
}
dirname ()
{
case $1 in
*/) dirname ${1%/} ;;
"") echo '/' ;;
*/*) echo "${1%/*}" ;;
*) echo '.' ;;
esac
}
export -f basename dirname
--
Chris F.A. Johnson address@hidden
=================================================================
address@hidden http://cfaj.freeshell.org
address@hidden http://members.rogers.com/c.f.a.johnson