Shell-Sprachen    up
  similar languages: DOS Batch  
 


 Squares   csh   Michael Neumann
# Comment in csh (not at the command-line!)
set i=1
while ($i <= 10)
  @ square=$i * $i
  echo -n $square ""
  @ i++
end
Outputs the squares from 1 to 10.


 Squares   es (Extensible Shell)   Michael Neumann
for (i=1 2 3 4 5 6 7 8 9 10) {
   echo -n `{ expr $i \* $i }' '
}
Outputs the squares from 1 to 10.


 Factorial   sh,ksh,zsh,bash   Michael Neumann
#! /bin/sh

#
# Calculates the factorial
#

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
Calculates the factorial. The call fac 6 results 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
Outputs the squares from 1 to 10.


 Hello World   sh,ksh,zsh,bash,csh,es   Michael Neumann
# Hello World!

echo Hello World
Prints "Hello World" onto the screen.


 Hello World   WSH (Windows Scripting Host)   Eric Vitiello
WScript.Echo "Hello World"
Prints "Hello World" onto the screen.


 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