On 13Sep2016 16:54, todd zullinger <tmz@xxxxxxxxx> wrote:
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.
I think that's a little subjective; I personally prefer the former.
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
Yeah, until you try to make it robust. Eg against a filename like
"temp4-take9.mp4", which your example will transmute into "temp3-take9.mp4",
not quite the plan. Whereas the "f%.mp4" thing will behave correctly because of
the greedy match.
(And yeah, if we were playing shell golf, it could be shortened to
"${f/%4/3}" -- but that's certainly not as legible.
Agreed there.
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. ;)
Ah, you've thought about this.
I tend to feel that glob-based things are better than regexp based things for
filename work, most of the time. Globs are simpler (albeit less powerful)
patterns and shorter and more readable and often more intuitive. (When they're
enough.)
Cheers,
Cameron Simpson <cs@xxxxxxxxxx>
--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://lists.fedoraproject.org/admin/lists/users@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org