Re: how to find the extension of a file?

From: Bill Seivert (seivert_at_pcisys.net)
Date: 02/28/05


Date: Sun, 27 Feb 2005 21:25:21 -0700


MDX wrote:
> Hi,
>
> I am trying to write a shell script which finds the extention of a file. I
> am doing it by manipulating the string. However, I hear the shell has tools
> that will output the extention of the file directly..
>
> Please advise
>
> Thanks in advance
> J
>
>

If you want just the very last extension, the following should work:
Given file=filename.ext,

extn=`expr "$file" : '.*\.\([^.][^.]*\)$'`

(untested)

Bill Seivert



Relevant Pages

  • Re: how to find the extension of a file?
    ... "MDX" wrote in ... > I am trying to write a shell script which finds the extention of ... I am doing it by manipulating the string. ... > hear the shell has tools that will output the extention of the ...
    (comp.unix.shell)
  • Re: how to find the extension of a file?
    ... On Mon, 28 Feb 2005 at 02:17 GMT, MDX wrote: ... > I am trying to write a shell script which finds the extention of a file. ... My code in this post is copyright 2005, Chris F.A. Johnson ...
    (comp.unix.shell)
  • Re: how to find the extension of a file?
    ... MDX wrote: ... >I am trying to write a shell script which finds the extention of a file. ... >am doing it by manipulating the string. ...
    (comp.unix.shell)
  • how to find the extension of a file?
    ... I am trying to write a shell script which finds the extention of a file. ... am doing it by manipulating the string. ...
    (comp.unix.shell)