[linux-l] zsh besser mit andere Sprache

Ivan Villanueva iv at artificialidea.com
So Okt 9 19:47:07 CEST 2005


Hallo Oliver,

On Sun, Oct 09, 2005 at 01:13:28PM +0200, Oliver Bandel wrote:
> Nimmt man für kleinere Sachen nicht Shell-Scripte?
> Und ansonsten Perl?
> 
> Was willst Du denn machen?

Ich brauche immer öfters kleine Programme, um etwas zu erledigen. Z.B. letztens
wollte ich alle Bilder in einem Verzeichnissbaum, die großer waren als 1024x...
Pixels, in 1024x... zu konvertieren. Das habe ich mit zsh erledigt:


#!/usr/bin/zsh
# Documentation of zsh: http://zsh.dotsrc.org/Guide/zshguide.html

if [[ $1 = '' ]] ; then
    print simage:error:You must specify a directory as first parameter
    exit 1
fi
if [[ ! -d $1 ]] ; then
    print simage:error:First parameter must be a directory
    exit 1
fi
if [[ $2 = '' ]] ; then
    print simage:error:You must specify a second parameter
    exit 1
fi
if [[ $2 -lt 16 ]] ; then
    print simage:error:second parameter must be a number greater than 16
    exit 1
fi

echo -n "All files in all subdirectories of $1 whose longest side is bigger than $2 pixels will be reduced. Are you sure ? "
read answer
if [[ $answer != y ]] ; then
    exit 0
fi

cd "$1"
for f in "${(f)$(find . )}" ; do
    fileType=$(file $f)
    if [[ $fileType = *image?data* ]] ; then
        height=$(identify -format "%h" $f)
        width=$(identify -format "%w" $f)
        if [[ ($height -gt $2) || ($width -gt $2) ]] ; then
            echo -n "simage : converting $f ... "
            mv "$f" "$f.bk"
            (convert -resize $2x$2 "$f.bk" "$f") || exit 1
            echo " done"
            (rm -f "$f.bk") || exit 1
        fi
    fi
done

-- 
Ivan F. Villanueva B.
The dream of intelligent machines: www.artificialidea.com
Encrypted mail preferred.
GPG Key Id: 3FDBF85F 2004-10-18 Ivan-Fernando Villanueva Barrio



Mehr Informationen über die Mailingliste linux-l