Am Montag, 5. November 2007 15:17:09 schrieb Axel Birndt:
Dirk schrieb:
for i in $1 do mv $1 $1_$DATIME
bin immer noch am Zweifeln, warum Du hier immer noch "$1" stehen hast...
$1 weil ich denke dass es der erste String nach dem scriptname ist
das ist im Prinzip auch richtig, aber $1 ist immer der komplette Übergabe-String. Dann frage ich mich allerdings, warum Du eine for-Schleife eröffnet hast ;)
füge mal nach dem ein Echo der Variablen ein for i in $1 do echo "i in der for-schleife: <$i>" echo "\$1 in der for-schleife: <$1>"
anbei etwas zur Bedeutung der Zeichenfolge "$irgendetwas" in einer Bourne-Shell (zitiert auis "man bash"): Special Parameters also hier geht's um das was einem $-Zeichen folgen kann The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. * Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a sin- gle word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" is equiva- lent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are sepa- rated by spaces. If IFS is null, the parameters are joined without intervening separators. also $* --> alle parameter (in erster Näherung) @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed). also $* --> alle parameter ( in erster Näherung) # Expands to the number of positional parameters in decimal. also $1, $2 , ..... $9 0 Expands to the name of the shell or shell script. This is set at shell initialization. If bash is invoked with a file of com- mands, $0 is set to the name of that file. If bash is started with the -c option, then $0 is set to the first argument after the string to be executed, if one is present. Otherwise, it is set to the file name used to invoke bash, as given by argument zero. also $0 == Name des ausgeführten Programmes, mit vorangestelltem Pfad (=Verzeichnis wo das Proggi gefunden wurde) Positional Parameters A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. also $1, $2 , ..... $9 Positional parameters are assigned from the shell's arguments when it is invoked, also wenn das Proggi "foo" mit den Argumenten a b c aufgerufen wird: foo a b c dann ist $0 = ./foo (wenn foo im aktuellen Verzeichnis gefunden wird) $1 = a $2 = b $3 = c and may be reassigned using the set builtin command. also: man kann im Skript schreiben: set x y z dann ist danach: $1 = x $2 = y $3 = z Positional parameters may not be assigned to with assignment statements. The positional parameters are temporarily replaced when a shell function is executed (see FUNCTIONS below). When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces (see EXPANSION below). also ${10}, ${11}, .... Der Unterschied zwischen $* und $@ ist subtil, aber wichtig Mehr dazu gibts hier: http://tldp.org/LDP/abs/html/othertypesv.html So long & bye Jürgen -- Dr.rer.nat. Juergen Vollmer, Viktoriastrasse 15, D-76133 Karlsruhe Tel: +49(721) 92 04 87 1 Fax: +49(721) 92 04 87 2 Juergen.Vollmer@informatik-vollmer.de www.informatik-vollmer.de Internet-Telefonie: www.skype.com Benutzer: juergen.vollmer -- Um die Liste abzubestellen, schicken Sie eine Mail an: opensuse-de+unsubscribe@opensuse.org Um eine Liste aller verfuegbaren Kommandos zu bekommen, schicken Sie eine Mail an: opensuse-de+help@opensuse.org