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"; doneYou 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.
Attachment:
signature.asc
Description: PGP signature
-- 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