CLI to turn a directory of images into Markdown links
Overview
Convert a directory of images to clickable Markdown links:
for i in `IMG_17*.jpg`; do echo $i | awk '{print "[](/images/" $1 ")"}'; done
Details
for i in...-> Loop over each file, placing filename in the variablei.ls -1 IMG_17*.jpg-> List files matching the filename pattern. Then feed into theforloop.echo $i-> Print the variablei.- awk (There are 2 key points, printing and variable expansion):
print-> Print everything after this statement to the screen. Text between"’s is printed as written.$(variables) are expanded and printed.$1-> Print the first match fromawk. In this case, print the filenames|‘ed throughawk.
jemurray@phalanges:~/Downloads $ for i in `IMG_17*.jpg`; do echo $i | awk '{print "[](/images/" $1 ")"}'; done
[](/images/IMG_1706.jpg)
[](/images/IMG_1707.jpg)
[](/images/IMG_1708.jpg)
[](/images/IMG_1711.jpg)
[](/images/IMG_1712.jpg)
[](/images/IMG_1713.jpg)
[](/images/IMG_1714.jpg)
[](/images/IMG_1715.jpg)
[](/images/IMG_1716.jpg)
[](/images/IMG_1717.jpg)
[](/images/IMG_1718.jpg)
[](/images/IMG_1720.jpg)
[](/images/IMG_1722.jpg)
The commands above generated this page: https://jasonmurray.org/posts/2021/firstlongphilmontprephike/