Help to debug autoconverter video to bash pliz

Gentlemen, trying to write a script that would check the presence of already converted file in the given folder and if it is not — coded. Probably the code will be easier to understand what I mean.
pastebin.com/C7aG2LEQ

Problem 12 the line, why it skips the check of an existing file, in the end, trying to re-encode it, which in General is absolutely not necessary for me to do, because files there in bulk. Prompt in what an error
October 8th 19 at 01:17
4 answers
October 8th 19 at 01:19
Solution
M, and as you place between the if and then there any team that wormed?
if [[ ! -e i.mp4 ]]
then 
echo "$i.mp4 not exist" 
echo "Converting "$i"." 
/usr/local/bin/ffmpeg -i ${video_folder}$i.mkv-acodec aac -strict experimental -ab 128k -ac 2-vcodec libx264 -b 1200k -s 1280x720 -r 30 -threads 0 ${films_folder}$i.mp4 ; echo "Convert "$i" to mp4 is done!"
fi

So everything is OK.

Well, I'm still a bit pozalusta:
for i in `ls-a $video_folder/*$file_mask*.mkv`

Don't ever do that, okay? Never! Suddenly you in the name spaces and all sorts of napechataem characters?
for i in $video_folder/*$file_mask*.mkv

That's so right.
i=$(echo $i | sed 's/.mkv//' | sed 's%^.*/%%')

OMG. guys here sed?
echo ${i/.mkv}

gonna work out fine.

Well, else shift'om unnecessary here.
Oh, and I forgot: "$i" "${i}" "${i/.mkv}" it is necessary not to forget to quote it. And if the space in the file name will be written, then kirdyk team. Error spit you out. - henri.Strosin commented on October 8th 19 at 01:22
October 8th 19 at 01:21
Why twice the square brackets?
October 8th 19 at 01:23
Bash script in 99% of cases should start with set-e. It is strange that nobody notice such glaring errors.
October 8th 19 at 01:25
If you have a message "${films_folder}$i.mp4 not exist" displays the correct file name, then try to move lines 13 and 14 to make a "then":
if [[ ! -e "${films_folder}$i.mp4" ]]
then
 echo "${films_folder}$i.mp4 not exist"
 echo "Converting "$i"."

 /usr/local/bin/ffmpeg -i ${video_folder}$i.mkv-acodec aac -strict experimental -ab 128k -ac 2-vcodec libx264 -b 1200k -s 1280x720 -r 30 -threads 0 ${films_folder}$i.mp4

 echo "Convert "$i" to mp4 is done!"
else
shift
fi

Find more questions by tags bashProgramming