Sunday, 30 December 2007; 03:46:19; Thomas Halinka: > ----> DA MACHT ER ES FÜR JEDES ZEICHEN Im 1. Script beginnst du die for-Schleife mit > for i in "$SRV" ... und im 2. Script beginnst du sie mit > for i in $SRV ... Die "formale" Definition einer for-Schleife ist laut man-page: for name [ in word ] ; do list ; done D.h. in der Variablen SRV stecken Worte, definiert als "(a) sequence of characters considered as a single unit by the shell." Um diese "einzelnen Einheiten" voreinander zu trennen, wird der Inhalt der Variablen IFS verwendet: "(t)he Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command." Der Vorgabe-Wert von IFS ist <space><tab><new-line>. Damit besteht z.B. "HTTP - WebMail" aus 3 Worten und dein 2. Script gibt das auch brav genauso aus. Im 1. Fall hast du die Variable SRV in Anführungszeichen. Damit schaltest du die Trennung entlang IFS ab. Mal ein Beispiel von hier (bashism ahead!): Erst baue ich mir eine "Liste": $ ping -c 3 localhost > test Von dem Ergebnis will ich nur die Zeilen "64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.048 ms" und davon nur hinten den Eintrag time samt Wert und Dimension. Also erstmal $ xox=$(grep icmp locping | cut -d ' ' -f 7-) Meine Variable xox entspricht nun in etwa deiner Variablen SRV. Es stehen 6 Worte drin (3x time=<wert> und 3 mal literal "ms"). Mit $ for i in $xox; do echo "$i"; done was deinem 2. Script entspricht, erhalte ich: time=0.048 ms time=0.038 ms time=0.037 ms was exakt der Ausgabe deines 2. Scripts entspricht. Mit $ for i in "$xox"; do echo "$i"; done erhalte ich die gewünschte Ausgabe time=0.048 ms time=0.038 ms time=0.037 ms was der Ausgabe deines 1. Scripts entspricht. HTH. Martin "vi"
Attachment:
signature.asc
Description: This is a digitally signed message part.