Wird das grep im Skript überhaupt benötigt?
sudo dpkg-query -s <PAKET>
erzeugt schon einen exit code 1 wenn das Paket nicht existiert.
Gruß BillMaier
|
Supporter
Anmeldungsdatum: Beiträge: 6497 |
Wird das sudo dpkg-query -s <PAKET> erzeugt schon einen exit code 1 wenn das Paket nicht existiert. Gruß BillMaier |
||
|
Supporter
Anmeldungsdatum: Beiträge: 55572 |
Eben nur dann. Wenn es existiert kriegst du nicht den Output, der gewünscht ist. 😉 Verkürzen kann man das dennoch, statt |
||
|
Supporter
(Themenstarter)
Anmeldungsdatum: Beiträge: 6497 |
$ ./check-package.sh bash
bash ist installiert
$ ./check-package.sh apache2
apache2 ist nicht installiert
$ ./check-package.sh gibtsnicht
gibtsnicht ist nicht installiert
$ cat check-package.sh
#!/bin/sh
PAKET=$1
if dpkg-query -s $1 >/dev/null 2>&1 ; then
echo "$PAKET ist installiert"
else
echo "$PAKET ist nicht installiert"
fi
Welcher ist denn gewünscht? |
||
|
Supporter
Anmeldungsdatum: Beiträge: 55572 |
Ohne deine Änderung: ./skritp.sh bash bash ist installiert Mit deiner Änderung: ./skript.sh bash Package: bash Essential: yes Status: install ok installed Priority: required Section: shells Installed-Size: 1588 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Architecture: amd64 Multi-Arch: foreign Version: 4.4.18-2ubuntu1 Replaces: bash-completion (<< 20060301-0), bash-doc (<= 2.05-1) Depends: base-files (>= 2.1.12), debianutils (>= 2.15) Pre-Depends: libc6 (>= 2.15), libtinfo5 (>= 6) Recommends: bash-completion (>= 20060301-0) Suggests: bash-doc Conflicts: bash-completion (<< 20060301-0) Conffiles: /etc/bash.bashrc 3aa8b92d1dd6ddf4daaedc019662f1dc /etc/skel/.bash_logout 22bfb8c1dd94b5f3813a2b25da67463f /etc/skel/.bashrc 1f98b8f3f3c8f8927eca945d59dcc1c6 /etc/skel/.profile f4e81ade7d6f9fb342541152d08e7a97 Description: GNU Bourne Again SHell Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). . Bash is ultimately intended to be a conformant implementation of the IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2). . The Programmable Completion Code, by Ian Macdonald, is now found in the bash-completion package. Homepage: http://tiswww.case.edu/php/chet/bash/bashtop.html Original-Maintainer: Matthias Klose <doko@debian.org> bash ist installiert
Steht doch unter der Echo-Angabe im Skript. |
||
|
Supporter
(Themenstarter)
Anmeldungsdatum: Beiträge: 6497 |
Der Output aus dem echo ist doch identisch. Außerdem $ ./check-package.sh bash
Package: bash
Essential: yes
Status: install ok installed
Priority: required
Section: shells
Installed-Size: 1588
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Multi-Arch: foreign
Version: 4.4.18-2ubuntu1
Replaces: bash-completion (<< 20060301-0), bash-doc (<= 2.05-1)
Depends: base-files (>= 2.1.12), debianutils (>= 2.15)
Pre-Depends: libc6 (>= 2.15), libtinfo5 (>= 6)
Recommends: bash-completion (>= 20060301-0)
Suggests: bash-doc
Conflicts: bash-completion (<< 20060301-0)
Conffiles:
/etc/bash.bashrc 3aa8b92d1dd6ddf4daaedc019662f1dc
/etc/skel/.bash_logout 22bfb8c1dd94b5f3813a2b25da67463f
/etc/skel/.bashrc 1f98b8f3f3c8f8927eca945d59dcc1c6
/etc/skel/.profile f4e81ade7d6f9fb342541152d08e7a97
Description: GNU Bourne Again SHell
Bash is an sh-compatible command language interpreter that executes
commands read from the standard input or from a file. Bash also
incorporates useful features from the Korn and C shells (ksh and csh).
.
Bash is ultimately intended to be a conformant implementation of the
IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).
.
The Programmable Completion Code, by Ian Macdonald, is now found in
the bash-completion package.
Homepage: http://tiswww.case.edu/php/chet/bash/bashtop.html
Original-Maintainer: Matthias Klose <doko@debian.org>
bash ist installiert
$ ./check-package.sh apache2
apache2 ist nicht installiert
$ cat check-package.sh
#!/bin/sh
PAKET=$1
if dpkg-query -s $1 2>/dev/null ; then
echo "$PAKET ist installiert"
else
echo "$PAKET ist nicht installiert"
fi Bin ich blind oder wofür brauch ich da das |
||
|
Anmeldungsdatum: Beiträge: 645 |
Alternativ-Vorschlag – garantiert ohne "grep" 😉 :
|
||
|
Supporter
(Themenstarter)
Anmeldungsdatum: Beiträge: 6497 |
kann man machen, aber was wird dadurch besser? |
||
|
Top-Wikiautor
Anmeldungsdatum: Beiträge: 2400 |
Wie schön, dass man viel machen kann. ☺ Eine weitere Möglichkeit wäre den Status direkt ab zu fragen „(seit Dpkg 1.17.11)“. dpkg-query -W -f='${db:Status-Status}\n' $PAKET Wenn sonst nichts wäre, würde mir die Ausgabe schon reichen. fleet@street ~ $ dpkg-query -W -f='${db:Status-Status}\n' grub-pc
installed
fleet@street ~ $ dpkg-query -W -f='${db:Status-Status}\n' lilo
not-installed
fleet@street ~ $ dpkg-query -W -f='${db:Status-Status}\n' fleet
dpkg-query: Kein Paket gefunden, das auf fleet passt
fleet@street ~ $ Ansonsten prüfen, ob die Ausgabe auch "installed" entspricht. #!/bin/bash
PAKET=$1
if [ "$(dpkg-query -W -f='${db:Status-Status}\n' $PAKET 2> /dev/null)" = "installed" ]
then
echo "$PAKET ist installiert"
else
echo "$PAKET ist nicht installiert"
fiDie Frage ist nur, ob jemand, der für die Überprüfung Anregung benötigt und daher diesen Wiki-Artikel liest, nicht mit der Pipe und grep schneller versteht, worum es geht. |
||
|
Supporter
(Themenstarter)
Anmeldungsdatum: Beiträge: 6497 |
Deine Abfrage gefällt mir. IMHO ein Fall für Skripte/Basheinzeiler |