[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: funktionen unter /bin/bash


On Tue, Nov 29, 2005 at 11:58:58PM +0100, Christian Eichert wrote:
> hi rabe
> 
> es geht mit darum wie man variablen unter bash an eine funktion schikt
> das ist die funktion
> 
>  function chopurl(??????) {
> 	[...]
> 	top=`basename $url`
> 	[...]
> }

Ich verwende innerhalb von Funktionen "positional parameters", 
also $1, $2, ... die im Kontext der Funktion gesetzt sind.
( bitte such' nach "^FUNCTIONS" in "man 1 bash" )

--------[bla.sh]--------------------------------
#! /bin/sh
foo() {
  echo "\$1= $1"
  echo "\$2= $2"
  echo "\$3= $3"
  echo "\$4= $4"
}

foo eins zwei drei vier
--------[/bla.sh]--------------------------------

Ausgabe:

$ ./bla.sh foo bar fasel
$1= eins
$2= zwei
$3= drei
$4= vier

HTH
 
MfG
-- 
Raphael Becker                                    http://rabe.uugrn.org/
                      http://schnitzelmitkartoffelsalat.und.rahmspin.at/
.........|.........|.........|.........|.........|.........|.........|..