home

Quickies, by Andrea Olivato

text

Create html for imgs in a folder using filename as alt in bash

This scripts generates the html code for all the images in a folder. It will use the filename, without extension and with some mods, as Alt attribute for the image.

#!/bin/bash

PATH_WWW="/img";
EXT="jpg"

for i in *.$EXT; do
        fname=$(basename $i .jpg);
        fname=${fname/_/ };
        fname=${fname/-/ };
        fname=${fname/./ };
        echo "<img src="$PATH_WWW/$i" alt="$fname" />"; 
done 

2 years ago

June 9, 2009
Comments (View)
blog comments powered by Disqus