| Shell-Sprachen
|
| ähnliche Sprachen: | DOS Batch | |
| Squares | csh | Michael Neumann |
# Kommentar in csh (nicht in der Kommandozeile!) set i=1 while ($i <= 10) @ square=$i * $i echo -n $square "" @ i++ end |
| Gibt die Quadrate von 1 bis 10
aus. |
| Squares | es (Extensible Shell) | Michael Neumann |
for (i=1 2 3 4 5 6 7 8 9 10) { echo -n `{ expr $i \* $i }' ' } |
| Gibt die Quadrate von 1 bis 10
aus. |
| Fakultät | sh,ksh,zsh,bash | Michael Neumann |
#! /bin/sh # # Berechnet die Fakultät # if [ $# != 1 ] then echo "FEHLER: Aufruf $0 Wert" >&2 exit 1 fi case $1 in [01]) echo $1 ;; *) n=`expr $1 - 1` m=`$0 $n` # $0 ist der Programm-Name echo `expr $1 \* $m` ;; esac |
Berechnet die Fakultät. Der
Aufruf fac 6 ergibt 720 |
| Squares | sh,ksh,zsh,bash | Michael Neumann |
squares= for i in 1 2 3 4 5 6 7 8 9 10 do squares=$squares`expr $i \* $i`" " done echo $squares |
| Gibt die Quadrate von 1 bis 10
aus. |
| Hello World | sh,ksh,zsh,bash,csh,es | Michael Neumann |
# Hello World! echo Hello World |
| Gibt "Hello World" auf dem Bildschirm
aus. |
| Hello World | WSH (Windows Scripting Host) | Eric Vitiello |
WScript.Echo "Hello World"
|
| Gibt "Hello World" auf dem Bildschirm
aus. |
| Bookmark Script | zsh | Michael Neumann |
#!/usr/bin/env zsh
#
# $Id: c,v 1.1 2001/07/20 18:18:10 michael Exp $
#
# Bookmark script for zsh
# by Michael Neumann (mneumann@ntecs.de)
#
# You have to type:
#
# fpath=(.) # or directory in which "c" lies
# autoload c
#
# to make sure, that the function c is
# invoked by zsh when you type "c".
#
dirs=(
/usr/pkgsrc
)
if [[ $# == 0 ]] ; then
cnt=1
for i in $dirs ; do
echo "[$cnt]\t$i"
cnt=`expr $cnt + 1`
done
else
# reload array dirs
if [[ $1 == -r ]] ; then
unfunction $0
autoload $0
else
nr=`expr $1 : '\([0-9]*\)$'`
if [[ $nr != '' ]] ; then # it's a number
if [[ $nr -le $#dirs && $nr -gt 0 ]] ; then
cd $dirs[$nr]
else
echo "False bookmark number"
fi
else
cnt=1
match_dirs=()
for i in $dirs ; do
if [[ `expr $i : '.*'$1` -gt 0 ]] ; then # matches entry
match_dirs[$cnt]=$i
cnt=`expr $cnt + 1`
fi
done
if [[ $#match_dirs == 0 ]] ; then
echo "Nothing found"
elif [[ $#match_dirs == 1 ]] ; then
cd $match_dirs[1]
pwd
else
cnt=1
for i in $match_dirs ; do
echo "[$cnt]\t$i"
cnt=`expr $cnt + 1`
done
echo -n "? "; read i
cd $match_dirs[$i]
fi
fi
fi
fi
|
| Bookmark Script |