Am Fre, 08 Jan 1999 schrieb system: Hallo System,
Das folgende BASH-Script ruft eine Oracle-Abfrage auf und liefert in $LINE entweder 0 oder einen Wert > 0.
Ich sehe das richtig? In LINE steht nur eine Zahl?
Wenn der Wert 0 ist soll das Script beendet werden.
1 ANZAHL=0 2 sqlplus -s $EMAILLOGIN v_status.sql | while read LINE
Ob Zeile 2 richtig ist weiß ich nicht. read als while-Bedinung ist merkwürdig, da es niemals fehlschlägt. Wenn das so sein soll, so ist doch while true und read nach dem do besser.
3 do 4 if (test $LINE ) then
hier gehören keine runde Klammern hin. Es wird gefragt, ob LINE nicht leer ist oder nicht. Möchtest Du eine Abfrage nach 0, so heißt das: if test $LINE -gt 0. Möchtest Du tatsächlich abfragen, ob LINE leer ist, so wäre if test -n $LINE besser,siehe help test. Auf jeden Fall gehöhrt then in die nächste Zeile. Oder ein Semikolon davor, was aber nicht so schön ist.
5 ANZAHL=`expr $LINE`
Was soll das Bezwecken? Wenn ANZAHL den Wert von LINE übernehmen soll, so reicht ANZAHL=$LINE. Aber warum nicht mit LINE weiterarbeiten. Was expr so alles kann siehe man expr.
6 fi 7 done
Nach dem done kommt die Shell nie mehr hin, da while immer true ist.
8 if ( test $ANZAHL -eq 0 ) then
Die runden Klammern sind überflüssig.
9 exit 0 10 fi
In Zeile 5 wird ANZAHL auf den Wert in $LINE gesetzt (z.B. 5). Das Funktioniert.
aber völlig kompliziert und nicht gut. s.o
Beim Vergleich in Zeile 8 hat ANZAHL jedoch wieder den Initialwertwert von Zeile 1.
Woher weißt Du das? So wie das Skript da steht kommt es niemals zu Zeile 8.
Welche Möglichkeiten habe ich, um ANZAHL global zu benutzen ?
export ANZAHL, ist hier aber unnötig.
oder wie kann man das Problem anders lösen ?
An der Bash-Programmierung muß Du noch einiges tun. Am Besten Du besorgst Dir ein Buch dazu. Ansonsten man bash info bash help bashbefehl und im Linuxanwenderhandbuch auf /usr/doc/Books steht schon eine ganze Menge. Das dürfte auch fürs erste reichen. Da brauchst Du noch nicht einmal Geld auszulegen. Aber keine Angst, daß machst Du schon. cu Bernd -- Bernd Brodeßer Mönchengladbach B.Brodesser@online-club.de -- Um aus der Liste ausgetragen zu werden, eine Mail an majordomo@suse.com schicken, mit dem Text: unsubscribe suse-linux