Re: Shell: for-schleife über Zeilen einer Datei

From: Oliver Fromme <olli(at)lurza.secnetix.de>
Date: Mon, 23 Feb 2009 12:32:20 +0100 (CET)

Timm Wimmers wrote:
> for INDEX in `cat <FILE>`; do
> echo $INDEX
> done

»Useless use of cat«, und die Backtick-Subshell ist auch
überflüssig. Leider ist »for x in `bla`« eher eine fragile
Konstruktion.

> Mit was muss ich "cat" ersetzen, damit _keine_ leeren Zeilen und
> Kommentare an die Schleife übergeben werden? Irgendwas gabs da mal, mir
> fällt es grad nicht ein.

Das kommt drauf an, was Du mit Kommentaren meinst; da
gibt es ja zahlreiche Varianten. Wenn Du z.B. alle
Zeilen weglassen willst, die ein »#« in Spalte 1 haben:

grep '^[^#]' <FILE> |
while read INDEX; do
        echo "$INDEX"
done

Gruß
   Olli

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd
"People still program in C.  People keep writing shell scripts.  *Most*
people don't realize the shortcomings of the tools they are using because
they a) don't reflect on their workflows and they are b) too lazy to check
out alternatives to realize there is help." -- Simon 'corecode' Schubert
To Unsubscribe: send mail to majordomo(at)de.FreeBSD.org
with "unsubscribe de-bsd-questions" in the body of the message
Received on Mon 23 Feb 2009 - 12:32:24 CET

search this site