On Wed, 14 Dec 2005 17:05, Nick Rout wrote: > On Wed, 14 Dec 2005 16:59:42 +1300 > > Steve Holdoway wrote: > > On Wed, 14 Dec 2005 16:49:59 +1300 > > > > Nick Rout <[EMAIL PROTECTED]> wrote: > > > Excellent, thanks > > > > > > Now, how do i turn a url like: > > > > > > http://server.com/path/to/sourcefile-2.3.4.tar.bz > > > > > > into just the filename like this: > > > > > > sourcefile-2.3.4.tar.bz > > > > file=`echo $url | sed 's?^.*/??'` > > > > Steve > > Yep, that works, (although don't ask me to explain it) > > so, it seems, does > > basename $url > > (basename I have seen used to strip out the path of a file on the > filesystem like > > # basename /path/to/file > file > > I didn't know until I just tried it that it also seems to strip out the > http://server.com part too. Sensible. Easy.
It's worth remembering the 'antonym', dirname, as well [EMAIL PROTECTED] ~/bible/pdf $ dirname \ http://server.com/path/to/sourcefile-2.3.4.tar.bz2 http://server.com/path/to [EMAIL PROTECTED] ~/bible/pdf $ basename \ http://server.com/path/to/sourcefile-2.3.4.tar.bz2 sourcefile-2.3.4.tar.bz2 Also basename will strip off the extension. vis:- [EMAIL PROTECTED] ~/bible/pdf $ basename \ http://server.com/path/to/sourcefile-2.3.4.tar.bz2 .bz2 sourcefile-2.3.4.tar -- CS
