the old spaces in file names thingy in shell scripts

Kurt Granroth kurt+plug-discuss at granroth.com
Wed Oct 10 17:59:59 MST 2007


Craig White wrote:
> My script breaks if the file names have spaces...
> 
> #!/bin/sh
> #
> BASE="/home/storage/users/craig/Desktop/dw"
> IN="in"
> OUT="out"
> for f in *.flv; do ffmpeg -i $f `basename $f.mp4 .flv`; done
> mv *flv $BASE/$IN
> mv *mp4 $BASE/$OUT
> 
> How can I fix this?
> 

Double quotes are your friend!

Hmm... I'd do it this way:

for f in *.flv;
do
  ffmpeg -i "$f" "${f%.flv}.mp4";
done

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : http://lists.PLUG.phoenix.az.us/pipermail/plug-discuss/attachments/20071010/8e156368/attachment.pgp 


More information about the PLUG-discuss mailing list