Re: pkg_delete `pkg_info|grep -i apache` --syntax fehler ?

From: Oliver Fromme <olli(at)lurza.secnetix.de>
Date: Wed, 18 Aug 2004 15:32:08 +0200 (CEST)

milius(at)milius.net <milius(at)milius.net> wrote:
> steht dort, dass man folgenden befehl ausführen soll: pkg_delete
> `pkg_info|grep -i apache` - hier nun meine versuche:

Wer die Doku geschrieben hat, hatte nicht viel Plan. :-)

Das kann so nicht funktionieren, da in der Ausgabe von
pkg_info neben dem Namen der Packages noch die Kurzbe-
schreibungen drinstehen. Auf meinem Rechner hier ergibt
das z.B. folgende Ausgabe:

$ pkg_info | grep -i apache
apache+mod_ssl-1.3.31+2.8.18_3 The Apache 1.3 webserver with SSL/TLS functionality
mod_perl-1.29 Embeds a Perl interpreter in the Apache server
mod_python-2.7.10 Apache module for integrating Python

Geschickter wäre es, nur die erste Spalte herauszuschneiden
(mit cut oder awk). Davon abgesehen ist das grep überflüs-
sig, da pkg_info auch Shell-Wildcards kennt, und mit der
Option -x auch reguläre Ausdrücke, wenn nötig.

Die Ausgabe dann mit Backticks in pkg_delete zu füttern,
ist auch suboptimal, denn das gibt eine Syntax-Fehlermel-
dung, wenn die Ausgabe leer ist (wenn kein Paket matcht).
Man sollte besser xargs verwenden; das ruft nämlich dann
pkg_delete gar nicht erst auf, wenn es keine Paketnamen
bekommt. Konkret also:

pkg_info -I "*apache*" | cut -f1 -c" " | xargs pkg_delete

Da aber pkg_delete ebenfalls Shell-Wildcards versteht (und
mit der Option -x Auch reguläre Ausdrücke), kann man sich
den ganzen Schmarrn gleich sparen:

pkg_delete "*apache*"

Das ist alles. Wichtig ist, daß man den Suchbegriff in
Anführungszeichen schreibt, damit die Wildcards nicht von
der Shell interpretiert werden, sondern von pkg_delete.

Gruß
   Olli

PS: Wie Backticks, Quoting u.ä. funktionieren, kannst Du
in der manpage Deiner Shell nachlesen, einfachstenfalls in
sh(1). Dies ist nicht FreeBSD-spezifisch. Selbstverständ-
lich gibt es auch manpages pkg_info(1) und pkg_delete(1).

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.
"... there are two ways of constructing a software design:  One way
is to make it so simple that there are _obviously_ no deficiencies and
the other way is to make it so complicated that there are no _obvious_
deficiencies."        -- C.A.R. Hoare, ACM Turing Award Lecture, 1980
To Unsubscribe: send mail to majordomo(at)de.FreeBSD.org
with "unsubscribe de-bsd-questions" in the body of the message
Received on Wed 18 Aug 2004 - 15:32:37 CEST

search this site