Indeed the script goes on immediately after the two loops, since they are executed in background. If you remove the ampersand at the end of the loops, they will be executed in foreground and the script will wait for completion before going on.
In that case the echo will be executed after the completion of the second loop, independently of its success. There are many ways to check if a command completed successfully, mainly by checking the
exit status of the command itself, but take in mind that mv fails every time it encounters a file without spaces and without uppercase characters (that is the file does not need to be renamed).
Regarding the .avi extension you can easily change it using
parameter substitution. For example:
Code:
nice -n 10 ffmpeg -i $i -ab 128 -ar 44100 ${i/.avi/.mp3}
Hope this helps.