my script works for a single file perfectly, but if I process multiple files, it deletes my workingfolder too early, and only one file is processed. If I don't delete the workingfolder, the script works with multiple files. Here is my script:
#!/bin/bash
cd /storage/sort_tv/
mkdir workingfolder
for i in *.mp4;
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
sudo ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy -map 0:a -map 0:v "workingfolder/${i%.*}.mp4" &&
mv -f workingfolder/* /storage/sort_tv
rm -rf workingfolder
done
How can I get all files to be processed AND moved before the working folder is removed?
sudo
? And whyrm -rf
instead ofrm -r
? – terdon Aug 05 '21 at 18:09sudo
is the one you should really avoid: that is creating files you don't own. And a generally good habit to get into is to never usesudo
unless it is necessary. – terdon Aug 06 '21 at 15:30rm -rf
will do for you. I highly doubt that is what you were shooting for. And that is just from a couple of weeks ago. It just happened to be in my history. – Nate T Aug 11 '21 at 16:18