[ale] stripping filename extension in bash

Jason Day jasonday at worldnet.att.net
Sat Nov 30 16:03:38 EST 2002


On Sat, Nov 30, 2002 at 03:45:08PM -0500, Christopher Bergeron wrote:
> Does anyone know how I can strip the extension from a filename in a bash 
> script?
> 
> Here's my script:
> 
> #!/bin/bash
> echo USE bergeron
> for i in `\ls *.jpg`

change this to:
  for i in *.jpg

> do
i=`echo $i | sed -e 's/\..*//'`
> echo "INSERT INTO pictures VALUES ('','$i','','','');"
> done

Note that this will ONLY work if all the filenames have only one '.' in
them.  If, for instance, you have a file called "foo.bar.jpg", it will
get translated to "foo", which is probably not what you want :) 
-- 
Jason Day                                       jasonday at
http://jasonday.home.att.net                    worldnet dot att dot net
 
"Of course I'm paranoid, everyone is trying to kill me."
    -- Weyoun-6, Star Trek: Deep Space 9
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list