rename v. script

Matthew Miller mattdm at mattdm.org
Fri May 20 20:48:56 UTC 2005


On Fri, May 20, 2005 at 04:36:41PM -0400, Steven W. Orr wrote:
>  > foo=/a/b/c/dee.f
>  > basename $foo
> dee.f
>  > dirname $foo
> /a/b/c
> 
> But you're much better off not using any external programs when you have 
> the choice of using real builtin stuff.
> 
>  > echo ${foo##*/} ${foo%/*}
> dee.f /a/b/c

Well, that depends on what you're going for. The built-in solution will be
trivially faster, and will obviously have no external dependencies, but it's
*much* harder to understand at a glance ("basename" and "dirname" are almost
self-documenting). And, while basename and dirname are quite standard unix
and can be pretty much expected to work anywhere, the fancy expansion syntax
you use won't work under /bin/sh on Solaris, say.

-- 
Matthew Miller           mattdm at mattdm.org        <http://www.mattdm.org/>
Boston University Linux      ------>                <http://linux.bu.edu/>
Current office temperature: 79 degrees Fahrenheit.




More information about the users mailing list