[ale] stripping filename extension in bash

Bob rstickel at bellsouth.net
Sat Nov 30 19:01:14 EST 2002


How about

n=$(( $(expr match "$i" '.*\.') - 1 ))
[ $n -gt 0 ] && i=${i:0:$n}


On Sat, 2002-11-30 at 15:45, 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`
> do
> echo "INSERT INTO pictures VALUES ('','$i','','','');"
> done
> 
> When run, the script produces lines like this:
> 
> INSERT INTO pictures VALUES ('','dsc01072.jpg','','','');
> INSERT INTO pictures VALUES ('','dsc01073.jpg','','','');
> 
> What i'd like to do is get $i without the .jpg extension at the end so 
> it would read:
> 
> INSERT INTO pictures VALUES ('','dsc01072','','','');
> INSERT INTO pictures VALUES ('','dsc01073','','','');
> 
> Does anyone have a simple awk or sed line to do this?
> 
> Thanks much!!!
> -CB
> 
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale


_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list