Re: OT: what does this expression mean?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux