the old spaces in file names thingy in shell scripts

Craig White craig at tobyhouse.com
Thu Oct 11 09:23:16 MST 2007


On Wed, 2007-10-10 at 21:06 -0700, Craig White wrote:
> On Wed, 2007-10-10 at 18:52 -0700, Dale Farnsworth wrote:
> > In article <1192062267.4942.89.camel at cube.tobyhouse.com> you write:
> > > 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
> > 
> > I don't think the above basename args do what you want.
> > 
> > > mv *flv $BASE/$IN
> > > mv *mp4 $BASE/$OUT
> > > 
> > > How can I fix this?
> > 
> > I think you want something like:
> > 
> > ===== begin script =======
> > #!/bin/sh
> > 
> > BASE="/home/storage/users/craig/Desktop/dw"
> > IN="in"
> > OUT="out"
> > 
> > for f in *.flv; do
> > 	MP4="`basename "$f" .flv`.mp4"
> > 	ffmpeg -i "$f" "$MP4"
> > 	mv "$f" "$BASE/$IN"
> > 	mv "$MP4" "$BASE/$OUT"
> > done
> > ===== end script =======
> ----
> I like this too - in fact, the two methods are highly instructive for
> me.
> 
> When the current batch is finished, I'm going to try this method out.
> 
----
just in case anyone tries to use this, the quotes are wrong on the MP4
line...this works...

#!/bin/sh
#
BASE="/home/storage/users/craig/Desktop/dw"
IN="in"
OUT="out"
for f in *.flv; do 
  MP4=`basename "$f" .flv`.mp4
  ffmpeg -i "$f" "$MP4"
  mv "$f" "$BASE/$IN"
  mv "$MP4" "$BASE/$OUT"
done

-- 
Craig White <craig at tobyhouse.com>



More information about the PLUG-discuss mailing list