2013/6/17 Luciano ES <lucm...@gmail.com>
> I agree that 'basename' doesn't quite cut it, and your request is fair.
>
> On the other hand, I think you have grown too accustomed to the quirk of
> one specific shell, although other shells have something similar.
>
> I would recommend you achieve what you want with sed, because it is really
> ubiquitous and will work in any shell. You may only realize how valuable
> that is after you have been through three or four shells, like I have
> (bash, ksh, tcsh and fish).
>
> So:
>
> set nameis (echo $dataset | sed 's/\([^.]\+\).*$/\1/')
>
I usually:
set nameis (echo $dataset | sed 's/\.[^.]*$//')
That renames "foo.bar.txt" to "foo.bar", whereas your snippet renames it to
"foo".
> Personally, I prefer this cleaner way:
>
> set nameis (echo $dataset | sed -r 's/([^.]+).*$/\1/')
>
> That solution also honors the old wisdom of The Unix Way, which is one
> dedicated tool for each specific task.
>
> An additional benefit of that approach is that you only have to learn the
> traditional Regular Expressions, not some dialect that no other language or
> tool uses.
>
> --
> Luciano ES
> >>
> **************************
> On Mon, 17 Jun 2013 13:31:18 +0200, aurelien coillet wrote:
>
> > Well thanks, I knew this solution, but it only works if you know the
> > extension of the file. What I'm looking for is something that remove
> > any extension suffix, whatever it is. So, your last line should give
> > "myfile" alone.
> >
> >
> > 2013/6/17 Stestagg <stest...@gmail.com>
> >
> > > One simple method would be to use basename:
> > >
> > > nameis=(basename $dataset .foo)
> > >
> > > this will perform the following,
> > >
> > > if $dataset = myfile then $nameis = myfile
> > > if $dataset = myfile.foo then $nameis = myfile
> > > if $dataset = /path/to/myfile.foo then $nameis = myfile
> > > if $dataset = /path/to/myfile.bar then $nameis = myfile.bar
> > >
> > > so provided you don't need absolute paths, this is simple.
> > >
> > > Steve
> > >
> > >
> > > On Mon, Jun 17, 2013 at 9:22 AM, aurelien coillet
> > > <acoil...@gmail.com>wrote:
> > >
> > >> Hi,
> > >>
> > >> How can I perform suffix removal as this (bash) command:
> > >>
> > >> nameis=${dataset%.*}
> > >>
> > >>
> > >> if dataset is a filename with extension (say foo.txt), nameis will
> > >> only contain "foo".
> > >> Is there a way to do that with fish?
> > >>
> > >> Thanks,
> > >>
> > >> --
> > >> Aurélien Coillet
> > >>
> > >>
> > >>
> ------------------------------------------------------------------------------
> > >> This SF.net email is sponsored by Windows:
> > >>
> > >> Build for Windows Store.
> > >>
> > >> http://p.sf.net/sfu/windows-dev2dev
> > >> _______________________________________________
> > >> Fish-users mailing list
> > >> Fish-users@lists.sourceforge.net
> > >> https://lists.sourceforge.net/lists/listinfo/fish-users
> > >>
> > >>
> > >
> >
> >
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users