I wanted to automate the process of fixing the indexing on some videos. Below is my code.
for f in ~/Videos/Temp/*
do
f=$(echo $f | sed 's/ /\\ /g')
name=$(echo $f | sed 's/Temp/Fixed/1')
mencoder -forceidx "$f" -o "$name" -oac copy -ovc copy
done
The problem I am having is that mencoder is claiming that it cannot find the file store in the variable $f.
MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
File not found: '/home/name/Videos/Temp/file\ name.avi'
Failed to open /home/bryan/Videos/Temp/file\ name.avi.
Cannot open file/device.
Exiting...
When I print the command to the terminal with the expanded variables and run it, it works just fine. I even modified my above code to print out the command for fixing each video, pasted that into a new script, and everything worked without a hitch. I am running this on Ubuntu. Any ideas as to what might cause this?
name. Variables should always be quoted when they're expanded (as you know).f=$(echo some file name); touch "$f"; ls "$f"returnssome file name. Butf2=$(echo $f | sed 's/ /\\ /g'); ls "$f2"returnsls: cannot access some\ file\ name: No such file or directory. (At least with bash 4.1.5.)