Hallo nochmals, 2006-06-06 23:21 +0200, Harry Rüter:
Es funktioniert, aber irgendwie stelle ich mir die Frage warum es mit dem return direkt aus der while-Schleife heraus nicht klappt.
Bisher war ich der Meinung, dass man mit return aus der Funktion rausspringt und mit break die Schleife beendet :o(
So sollte es auch sein (Auszug aus 'man return'): "return [n] Causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command executed in the function body. If used outside a function, but during execution of a script by the . (source) command, it causes the shell to stop executing that script and return either n or the exit status of the last command executed within the script as the exit status of the script. If used outside a function and not during execution of a script by ., the return status is false." Ich habe dein Skript gedebuggt (gibt's so ein Wort?) und zwei 'echo'-Befehle eingefügt: --- cut here --- if [ "a$NAME" = "a$WHAT" -a "a$PORT" = "a$PPORT" ] then echo "Hier bin ich!" <--- HIER... return 1 fi done echo "Hier bin ich wieder!" <--- ... UND HIER return 0 --- cut here --- Ausgeführt so dass etwas gefunden wird:
sh harry.sh Hier bin ich! Hier bin ich wieder!
Also mit return wird nur die Schleife (while) beendet und man landet auf die Zeile nach 'done'. Die Erklärung dafür scheint zu sein, dass - AFAIK - pipes als "child processes" ausgeführt werden, so dass die while-Schleife als child-Prozess ausgeführt und entsprechend mit dem ersten 'return' beendet wird. Gruß Kimmo -- Um die Liste abzubestellen, schicken Sie eine Mail an: suse-linux-unsubscribe@suse.com Um eine Liste aller verfuegbaren Kommandos zu bekommen, schicken Sie eine Mail an: suse-linux-help@suse.com