Anthony Joseph Messina wrote:
On Monday, September 12, 2016 12:22:48 PM CDT Mike Wright wrote:
> for f in "$(ls *.mp4)"; do
> ffmpeg -i "$f" -c:a libmp3lame "${f%.mp4}.mp3";
> done
You shouldn't need ls...
Indeed. Parsing ls is almost never a good idea.
for f in *.mp4; do
ffmpeg -i "$f" -c:a libmp3lame "${f%.mp4}.mp3";
done
While we're at it, I might suggest that "${f%.mp4}.mp3" isn't as clear
as "${f/.mp4/.mp3}" for this particular for loop.
The pattern substitution method ${parameter/pattern/string} will also
look more familiar to anyone who has used s/pattern/subst/ in vim,
perl, etc, which is a small bonus.
for f in *.mp4; do
ffmpeg -i "$f" -c:a libmp3lame "${f/.mp4/.mp3}";
done
(And yeah, if we were playing shell golf, it could be shortened to
"${f/%4/3}" -- but that's certainly not as legible. Saving those few
characters is likely not worth having to remember that /% means "match
at the end of the parameter." Although, using the % to anchor the
substitution would be the most prudent thing even when using the full
extension, in case you had a file with .mp4 elsewhere in the name. ;)
--
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In some cultures what I do would be considered normal.