shell script の例

機能 : カレントディレクトリにある JPEG ファイルから gif サムネール付き html ファイルを出力する
動作環境 : sh と ImageMagic の convert が動作する環境

#!/bin/sh
convert=/usr/local/bin/convert
convert_opt="-normalize -geometry 96x96"
outfile=index.html
title=`pwd`
if [ "$title" = "/" ]; then
    echo ${0##*/} : Execution on the root directory is prohivited.
    exit 1
fi

{   echo "<HTML>"
    echo "<HEAD>"
    echo "<TITLE>${title##*/}</TITLE>"
    echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=x-sjis\">"
    echo "</HEAD>"
    echo "<BODY text=\"#000000\" bgcolor=\"#ffffff\">"
    for src in *.jpg; {
        dest=${src%.jpg}.gif
        echo "<a href=\"./$src\"><img src=\"./$dest\" alt=\"$src\"></a>"
    }
    echo "</BODY>";
    echo "</HTML>";
}>$outfile

echo ${0##*/} : $outfile
for src in *.jpg; {
    dest=${src%.jpg}.gif
    echo ${0##*/} : $src -\> $dest
    nice $convert $src $convert_opt $dest
}
echo ${0##*/} : done.

www.finetune.co.jp [Mail] © 2000 Takayuki HOSODA.