[SATLUG] Bash scripting noob could use some help with a Bash script

Don Davis dondavis at reglue.org
Sun May 30 09:54:34 CDT 2010

  How do I get that to work? How do I remove the file
> extension from $f?

Have a look at sed, regular expressions, grep, and awk.
They are the duct tape and flat head screwdrivers of scripting.

for i in *wmv; do ffmpeg -i $i -ss 78.5 -s 640x352 -vframes 1 -an -f 
image2 `echo $i | sed 's/\(.*\)\.[A-Za-z]\{3\}/\1/'`_preview.jpg; done

Here -> sed 's/\(.*\)\.[A-Za-z]\{3\}/\1/'`_preview.jpg; done

\. signifies escaping the dot so it's a dot and not 'any character'

[A-Za-z]{3}  signifies any combination of 3 upper or lowercase letters; 
you could replace it with \.mov

back ticks contain the subroutine and returns the data. $(echo $i | sed 
's/\(.*\)\.[A-Za-z]\{3\}/\1/')_preview.jpg; done

$() works as well. The preferred usage is now $(). However, I don't 
remember enough to explain why...

More information about the SATLUG mailing list