[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: basename sucks
From: |
Bob Proulx |
Subject: |
Re: basename sucks |
Date: |
Fri, 2 Feb 2007 09:37:32 -0700 |
User-agent: |
Mutt/1.5.9i |
Alfred M. Szmidt wrote:
> echo /home/me/foo | xargs -l basename
> foo
>
> When doing the filter trick, you'd end up forking three new processes
> each time. Which can cause quite a serious slow down in some scripts.
Then Mike's suggestion of using the shell directly is the best choice
for efficiency. No process forks and everything is done internally to
the shell. It should be quite fast.
dirname - ${foo%/*}
basename - ${foo##*/}
> IMHO, yes, they are. Specially if you have to do it a couple times in
> different scripts. But not so painful that I will submit a patch for
> basename. :-)
I am not fundamentally opposed to a basename as a filter but it just
seems like a lot of work for a small return. Besically in the shell
the use of dirname and basename are going to be less efficient because
they are silly things to begin with. It is a very simple operation
and there are whole external commands for doing it? Wow.
If one is looking for efficiency then using a shell built-in is best
so perhaps getting dirname and basename built into the shell is
reasonable. If one is looking for readability or programmer
productivity then using them as they are make sense.
Or perhaps one should use a fully shell replacement such as this bash
snippet that is also a filter?
basename()
{
if [ $# -eq 0 ]; then
while read arg; do
echo ${arg##*/}
done
else
local tmp=${1##*/}
echo ${tmp%$2}
fi
}
Bob
- Re: basename sucks, (continued)
- Re: basename sucks, Eric Blake, 2007/02/01
- Re: basename sucks, Alfred M. Szmidt, 2007/02/01
- Re: basename sucks, Eric Blake, 2007/02/01
- Re: basename sucks, Alfred M. Szmidt, 2007/02/01
- Re: basename sucks, Evan Hunt, 2007/02/01
- Re: basename sucks, Matthew Woehlke, 2007/02/01
- Re: basename sucks, Alfred M. Szmidt, 2007/02/01
- Re: basename sucks, Mike Frysinger, 2007/02/01
- Re: basename sucks, Bob Proulx, 2007/02/01
- Re: basename sucks, Alfred M. Szmidt, 2007/02/02
- Re: basename sucks,
Bob Proulx <=
- Re: basename sucks, Matthew Woehlke, 2007/02/02
- Re: basename sucks, Mike Frysinger, 2007/02/02
- Re: basename sucks, Matthew Woehlke, 2007/02/02
- Re: basename sucks, Andreas Schwab, 2007/02/02
- Re: basename sucks, Mike Frysinger, 2007/02/02
- Re: basename sucks, Andreas Schwab, 2007/02/02
Re: Re: basename sucks, dusan halicky, 2007/02/01