Bash for loops

bash file listing with markup

every now and again we need to take a bunch of file names from a folder and output then into a single file. sometimes with markup around them. Well there’s always ls.

ls > test.txt

this nets you the following in a file:

0.png
1.png
blockcontent_h.png
blockcontent_s.png
blockcontent_v.png
blockheader.png

what if you want markup around the file names? like a list of all images in a folder with html tags around it. well things get slightly more involved. say you have a bunch of png files and want them listed in an html file with img tag and span tags so you can add css classes to it.

for i in *.png; do echo "\t\r\t\t<img src="$i" alt="" />\r\t"; done > images.html

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *